顶部滚动未定义在shopify网站

问题描述 投票:1回答:1

我工作的一个电子商务商店(shopify /液体)。

我想顺利滚动到不同的哈希值。

现在,因为这是一个CMS,我曾通过编辑器或手动JS添加一些属性。

在这里,我给它的href

$(document).ready(function() {
    $(".hero__cta").addClass("scroll");
    $(".hero__cta").attr("href", "#section2")
});

如果你去的网站,只需在主图像,@the新条目@称号,这是该标记:

<a id="section2"> </a>

这里是JS功能:

$(document).ready(function(){
    $("a").on('click', function(event) {
        if (this.hash !== "") {
            event.preventDefault();
            var hash = this.hash;
            $('html, body').animate({scrollTop: $(hash).offset().top}, 800,
                function() {                
                window.location.hash = hash;
                }
            );
        }
    });
});

所以,如果你去的网站,并点击按钮CTA,它应该顺利滚动到该锚点。工作在一个Codepen等,但不包括Shopify平台上。

我得到:

遗漏的类型错误:在HTMLAnchorElement无法读取的未定义的属性“顶”。

该网站是住在这里:

https://www.toptrendshopping.com/

哦,如何和我在哪里添加一个路口观察填充工具的呢?

javascript jquery shopify liquid
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.