0
jQuery.fn.extend({
      scrollTo : function(speed, easing) {
        return this.each(function() {
          var targetOffset = $(this).offset().top;
           $.fx.off = true;
          $('html,body').animate({scrollTop: targetOffset}, speed, easing);

        });
      }
    });
    $(document).keyup(function(e) 
    {

    if(e.keyCode == 78) { 
        navigation_x();
    }

    function navigation_x(){
    $('div#images-interface-controller').scrollTo(1000);

}

所以我有这个keyup功能,每次我按下字母“n”它都会滚动到div#images-interface-controller,是的,它正在滚动,但直到'到div#images-interface-controller的最后一个元素。我怎样才能停止它,我的意思是我希望它每次按“n”时一次只滚动 1 个。我猜想 jquery 代码上方的 .each 与我的问题有关。任何帮助将不胜感激。谢谢!

无论如何,我正在使用这个插件: http: //flesler.blogspot.com/2007/10/jqueryscrollto.html

4

1 回答 1

0

我以前用过这个插件,但已经有一段时间了。我想你想要这个。

$(window).scrollTo('#images-interface-controller', 1000);

调用的选择器scrollTo()是进行滚动的项目,而作为第一个参数传递的选择器是您希望第一个项目滚动到的对象。

这是告诉window滚动到某个项目,特别是带有idof的 div images-interface-controller

于 2012-07-22T12:39:48.717 回答