2012-02-04 3 views
1
<div class="page"> 
     div content 
</div> 

<script> 

if(scroll mouse up while hovering #page) 
$('.page').animate({'left':'+40px'}); 

if(scroll mouse down while hovering #page) 
$('.page').animate({'left':'-40px'}); 

</script> 

위의 예와 같이하고 싶습니다. 누군가 나를 도울 수 있습니까?div에서 마우스 스크롤을 사용하여 애니메이션을 트리거 하시겠습니까?

+0

var tempScrollTop, currentScrollTop = 0; $('#div').scroll(function() { currentScrollTop = $('#div').scrollTop(); if (tempScrollTop < currentScrollTop) { // UP } else if (tempScrollTop > currentScrollTop) { // DOWN } tempScrollTop = currentScrollTop; } 

코멘트에서 촬영 "당신의 질문 중 실제로 질문을하지 않는 이유는 무엇입니까? –

답변

2

당신은 this mousewheel plugin을 사용하고 있습니다 :

$('.page').mousewheel(function(event, delta) { 
    event.preventDefault(); // if you want to prevent the window from scrolling 

    $(this).animate({left: (delta>0 ? '+' : '-')+'40px'}); 
}); 
+0

고마워요, 완벽하게 작동합니다! –

관련 문제