2010-05-19 51 views
2

我想知道我可以如何解決以下問題。jquery - >尋找元素和導航throug?

我有並排浮動div(.picture_holder)的水平滾動條。我不知道我是否可以找到()這個元素,並將滾動事件動畫到每個圖像的起始點。如果我到達最後一個div,它會滾動到第一個。

# 
$('.next').click(function(){ 
# 
$('html, body').animate({scrollTo:Position von .picture_holder2}, 'slow'); 
# 
}); 

?? ??任何想法如何我可以解決這個問題?

回答

0

您可以使用jQuery的.scrollLeft()函數水平滾動到某個位置。

http://api.jquery.com/scrollLeft/

如果你想它的動畫,這樣做:

活生生的例子:http://jsfiddle.net/b5Xps/

$('.next').click(function(){ 

     // Get left offset position of the target 
    var leftPosition = $('.picture_holder2').offset().left; 

     // animate the scrollLeft property to that position 
    $('html,body').animate({scrollLeft: leftPosition }, 1000);​ 

});