2012-02-04 80 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; } 

从评论摘自“类似于”为什么你的问题实际上没有提出具体的问题? – 2012-02-08 14:03:55

回答

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

谢谢,完美的作品! – 2012-02-05 08:24:12