jQuery -滚动到一个由变量计算的位置

jQuery - Scrolling to a location calculated by a var

本文关键字:一个 变量 计算 位置 滚动 jQuery      更新时间:2023-09-26

我有以下脚本:

$('.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和平滑滚动插件来完成此操作,但我无法让它与我的$matchingDIV输出一起工作。

完成这个最简单的方法是什么?

尝试将htmlbodyscrollTop属性动画化:

$("html, body").animate({ scrollTop: $matchingDIV.offset().top }, delay);