我这里有一个 jQuery SlideDown/SlideUp 演示:https://tinker.io/8e585/15
当我点击“测试 2”链接时,是否有可能视口(viewport)向下移动到页面的该部分?那么“测试 2”就会出现在窗口顶部?
我尝试过:$(window).scrollTop($('div#box2').offset().top)
,但在 FF 中遇到问题。
有什么简单的解决方案吗?
非常感谢:-)
最佳答案
试试这个:
$("#box2 h2").click(function () {
var $this = $(this);
$('html, body').animate({
scrollTop: $this.offset().top
}, 1000);
return false;
});
关于javascript - 更新基本 jQuery 脚本以使用 ScrollTo 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14456506/