I am working on an ecommerce store(shopify/liuquid).
I want to scroll smoothly to different hashs.
Now because this is a CMS, I have had to add some attributes via editor or manually with JS.
Here I give it the href
$(document).ready(function() {
$(".hero__cta").addClass("scroll");
$(".hero__cta").attr("href", "#section2")
});
If you go to the website, just under the main image, @the new entries@ title, has this is the markup:
<a id="section2"> </a>
And here is the JS function:
$(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;
}
);
}
});
});
So if you go to the site and click on the CTA button, it should scroll smoothly to that anchor. Works on a Codepen etc, but not on the Shopify platform.
I get :
Uncaught TypeError: Cannot read property 'top' of undefined at HTMLAnchorElement.
The site is live here:
https://www.toptrendshopping.com/
Oh and how and where do I add an IntersectionObserver polifill for this?