I am hoping someone can help me with detecting if the cart is open are not. The problem I am having is i have added a “back to top” button found here in the discussions that works well save it is displayed when the cart is open and sometimes blocks info contained in the cart.
I found where it will choose to display based on scrolling however I want to add an “if” statement to not display it if the cart is open, (please see screenshot).
liquid code example:
function trackScroll() {
var scrolled = window.pageYOffset;
var coords = {{ vertical_offset_for_trigger }};
if (scrolled > coords) { goTopBtn.classList.remove(‘hide’); }
if (scrolled < coords) { goTopBtn.classList.add(‘hide’); }
}
I would like to add something like:
if (Cart detection code) {
goTopBtn.classList.add(‘hide’);
}
You don’t need to use JavaScript code to check if the drawer is open. You can use this CSS code to make your back-to-top button not appear if your cart drawer is open. Please add your code to theme.liquid file, after
I’d rather use display: none; instead of opacity:0;
With opacity:0 the element is still there (even though it’s transparent) and may potentially cover some buttons or links preventing them from functioning.
For example, here the button would not be visible but still prevent removing Wine packaging from the cart