更新基本的jQuery脚本使用ScrollTo功能

问题描述:

我有一个jQuery了slideDown /效果基本show演示在这里:https://tinker.io/8e585/15更新基本的jQuery脚本使用ScrollTo功能

是否有可能,当我点击“测试2”链接,视向下移动到的那部分页面?那么'测试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; 

}); 

工作演示:https://tinker.io/8e585/16

+0

哇!这很好用。非常感谢花时间帮助并给出了这样一个准确的答案。 – michaelmcgurk