平滑滚动到 div id jQuery [英] Smooth scroll to div id jQuery
本文介绍了平滑滚动到 div id jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试滚动到 div id jquery 代码才能正常工作.基于另一个堆栈溢出问题,我尝试了以下操作
I've been trying to get a scroll to div id jquery code to work correctly. Based on another stack overflow question i tried the following
演示 http://jsfiddle.net/kevinPHPkevin/8tLdq/
$('#myButton').click(function() {
$.scrollTo($('#myDiv'), 1000);
});
但是没有用.它只是捕捉到 div.我也试过
But it didn't work. It just snaps to the div. I also tried
$('#myButton').click(function(event) {
event.preventDefault();
$.scrollTo($('#myDiv'), 1000);
});
毫无进展.
推荐答案
您需要为 html, body
演示 http://jsfiddle.net/kevinPHPkevin/8tLdq/1/>
$("#button").click(function() {
$('html, body').animate({
scrollTop: $("#myDiv").offset().top
}, 2000);
});
这篇关于平滑滚动到 div id jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文