2010-11-18 4 views
2

지금까지 나는 120 번씩 클릭하여 아래로 내려갈 수 있도록 만들었지 만, 아래로 내려가는 것이 아니라 위아래로 가고 싶습니다. 나는 이것을 설명하여 "누군가"가 이해할 수 있기를 바랍니다.jQuery.click. 아래로 이동하여 애니메이션을 백업합니다.

<script> 
    $(document).ready(function() { 
    $('#footertab').click(function() { 
     $('#footer').animate({ 
     bottom: '-=120' 
     }, 1000, function() { 
     // Animation complete. 
     }); 
    }); 
    }); 
    </script> 
+0

토글 또는 1 초 동안 아래로 움직이기를 원하나요? – JonVD

+0

죄송합니다. 덕분에 –

답변

6

내가이 권리를 얻으면, 바닥 글의 위치를 ​​토글하려고합니다. 이것은 .toggle() 함수로 할 수 있습니다 :

$(document).ready(function() { 
    $('#footertab').toggle(function() { 
    $('#footer').animate({ 
     bottom: '-=120' 
    }, 1000); 
    },function() { 
    $('#footer').animate({ 
     bottom: '+=120' 
    }, 1000); 
    }) 
}); 
+0

약간의 구문 오류가 있습니다.}, 10 행)} 완벽하게 작동합니다! –

+0

이 .toggle()의 사용은 jQuery 1.8/1.9부터 [deprecated/removed] (http://api.jquery.com/toggle-event/)되었습니다. – brennan

2

당신은 이것에 대한 .toggle()를 사용할 수 있습니다

$(function() { //shortcut for $(document).ready(function() { 
    $('#footertab').toggle(function() { 
    $('#footer').animate({ bottom: '-=120' }, 1000); 
    }, function() { 
    $('#footer').animate({ bottom: '+=120' }, 1000); 
    }); 
}); 

.toggle()를 사용하여 모든 click 이벤트는 -=+= 애니메이션을 실행 사이를 전환합니다. 또한 애니메이션 콜백을 포함 할 필요가 없다면 아무것도하지 않고 그냥 놔두십시오.

0
<script> 
    $(document).ready(function() { 
    $('#footertab').toggle(
     function() { 
     $('#footer').animate({ 
      bottom: '-=120' 
     }, 1000, function() { 
      // Animation complete. 
     }); 
     }, 
     function() { 
     $('#footer').animate({ 
      bottom: '+=120' 
     }, 1000, function() { 
      // Animation complete. 
     }); 
     }, 
    ); 
    }); 
    </script> 
관련 문제