[英]How to smooth scroll on click jquery
I want to be able to smooth scroll to a specific div using its id but my current script isn't correct. 我希望能够使用其ID平滑滚动到特定的div,但是我当前的脚本不正确。 Can anyone see where my error is? 谁能看到我的错误在哪里?
Here is my fiddle for reference here . 这里是我的小提琴参考这里 。
<script>
$(document).ready(function() {
$('a').click(function(){
$('html, body').animate({
scrollTop: $( $.attr(this, 'href') ).offset().top
}, 5000);
return false;
});
});
</script>
Thanks. 谢谢。
no need to add script tag in jsfiddle. 无需在jsfiddle中添加脚本标签。 Try with this fiddle. 试试这个小提琴。 http://jsfiddle.net/wn6rv94t/1/ Removed <script></script>
http://jsfiddle.net/wn6rv94t/1/删除了<script></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.