Javascript 当产品详细信息页面有产品库时,滚动至div not working

Javascript 当产品详细信息页面有产品库时,滚动至div not working,javascript,jquery,wordpress,woocommerce,Javascript,Jquery,Wordpress,Woocommerce,在jquery中向上滚动不工作 我正在使用 提供WooCommerce插件(版本1.4.9) WooCommerce(版本3.4.3) WordPress(版本4.9.6) 提供插件在商店页面上添加提供按钮,当我们单击该按钮时,它将重定向到产品的“提供”选项卡 为此,我们在js文件中使用了scrollTop函数。 这是代码 var targetTab = $(".tab_custom_ofwc_offer_tab"); $('html, body').animate({ scroll

在jquery中向上滚动不工作

我正在使用

  • 提供WooCommerce插件(版本1.4.9)
  • WooCommerce(版本3.4.3)
  • WordPress(版本4.9.6)
提供插件在商店页面上添加提供按钮,当我们单击该按钮时,它将重定向到产品的“提供”选项卡

为此,我们在js文件中使用了scrollTop函数。 这是代码

var targetTab = $(".tab_custom_ofwc_offer_tab");
$('html, body').animate({
    scrollTop: $(targetTab).offset().top - '100'
}, 'fast');
虽然WooCommerce产品页面有产品库,但它不会滚动到该特定分区。 请看图片:

这是本期的视频链接:

点击观看上述事件发生的视频


如能提供任何有关这方面的信息,将不胜感激。谢谢

您的代码中有一个问题

试试这个

var targetTab = $(".tab_custom_ofwc_offer_tab");
    $('html, body').animate({
        scrollTop: $(targetTab).offset().top - '100'
    }, 'fast');

您将从jQuery中访问元素两次,从此变量$(targetTab)中删除jQuery

var targetTab = $(".tab_custom_ofwc_offer_tab");
$('html, body').animate({
    scrollTop: targetTab.offset().top - '100'
}, 'fast');

您可以尝试将其包装在延迟为0的setTimeout中吗?i、 e等到要呈现的元素之后再滚动不,问题中的代码没有结构化,我尝试添加您的代码,但没有成功,因为我们有相同的代码。