Javascript jQuery-滚动到由变量计算的位置
我有以下脚本:Javascript jQuery-滚动到由变量计算的位置,javascript,jquery,scroll,Javascript,Jquery,Scroll,我有以下脚本: $('.how-we-do-it .items div').on('click', function () { var $matchingDIV = $('.how-we-do-it .sections .section .content div.' + $(this).attr('class')); $matchingDIV.toggle('fast'); }); 我一直在尝试添加一些额外的代码,以便页面自动向下滚动到被切换的$matchingDIV 我一直在
$('.how-we-do-it .items div').on('click', function () {
var $matchingDIV = $('.how-we-do-it .sections .section .content div.' + $(this).attr('class'));
$matchingDIV.toggle('fast');
});
我一直在尝试添加一些额外的代码,以便页面自动向下滚动到被切换的$matchingDIV
我一直在尝试使用scrollTop和Smooth Scroll插件来实现这一点,但我无法让它与我的$matchingDIV输出一起工作
实现这一点最简单的方法是什么?尝试设置
html
和正文的scrollTop
属性的动画:
$("html, body").animate({ scrollTop: $matchingDIV.offset().top }, delay);