简体   繁体   English

ScrollTo div代码不起作用?

[英]ScrollTo div code not working?

please see this fiddle http://jsfiddle.net/rabelais/Lsbnyntg/1/ 请参阅此小提琴http://jsfiddle.net/rabelais/Lsbnyntg/1/

When the user clicks on one of the essay links the page should scroll to the top of the essay. 当用户单击文章链接之一时,页面应滚动到文章顶部。 However there is no scrolling motion happening, it just quickly jumps to the div. 但是,没有滚动动作发生,它只是快速跳转到div。 I have tried playing with the animation time but it does not seem to effect it. 我尝试过播放动画时间,但似乎没有影响它。 How can I make the scrolling visible? 如何使滚动可见?

$('ul.inner-li-texts li a').on('click', function(event) {

     var target = $(this.href);

     if ( target.length ) {

         event.preventDefault();
         $('html, body').animate({
              scrollTop: target.offset().top
         } 0, 10000);

     }

});

You first selector is incorrect: 您的第一个选择器不正确:

$('ul.inner-li-texts li a')

should be 应该

$('#inner-li-texts li a')

You have a typo in your animate statement. 您的动画语句中有错字。

Your target code does not work, it should look something like this: 您的target代码不起作用,它应该看起来像这样:

$('#inner-li-texts li a').on('click', function(event) {

     var target = $($(this).attr('href'));

     if ( target.length ) {

         event.preventDefault();
         $('html, body').animate({
              scrollTop: target.offset().top
         }, 10000);

     }

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM