【问题标题】:jquery -> finding elements and navigating throug?jquery - >查找元素并导航?
【发布时间】:2010-05-19 20:33:49
【问题描述】:

我想知道如何解决以下问题。

我有一个并排浮动 div 的水平滚动条 (.picture_holder)。我想知道我是否可以找到()这些元素并将滚动事件动画到每个图像的起点。如果我到达最后一个 div,它会滚动到第一个。

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

??有什么想法可以解决这个问题吗?

【问题讨论】:

    标签: jquery find


    【解决方案1】:

    我的解决方案?不要重新发明scrollable

    【讨论】:

      【解决方案2】:

      您可以使用 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);​
      
      });  
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-01
        • 2012-10-05
        • 1970-01-01
        • 2018-07-23
        相关资源
        最近更新 更多