I've successfully set up the Shopify Ajax Cart using the Timber framework so currently my cart closes if you click anywhere outside of the cart (or using the close button).
I was wondering if it was possible to have the cart close should the user start to scroll after they have added an item to the cart. I found another theme - Beatnik - which achieves this but not being great with JS, I'm not sure where to begin.
I've realised that when the cart is open the rest of the site isn't scrollable so I'm wondering if this is why I'm having trouble getting it to scroll?
Some of my current code as follows, see Timber framework for same setup as mine:
theme.liquid -
{% comment %}
Ajaxify your cart with this plugin.
Documentation:
- http://shopify.com/timber#ajax-cart
{% endcomment %}
{% if settings.ajax_cart_enable %}
{{ 'handlebars.min.js' | asset_url | script_tag }}
{% include 'ajax-cart-template' %}
{{ 'ajax-cart.js' | asset_url | script_tag }}
<script>
jQuery(function($) {
ajaxCart.init({
formSelector: '#AddToCartForm',
cartContainer: '#CartContainer',
addToCartSelector: '#AddToCart',
cartCountSelector: '#CartCount',
cartCostSelector: '#CartCost',
moneyFormat: {{ shop.money_format | json }}
});
});
jQuery('body').on('ajaxCart.afterCartLoad', function(evt, cart) {
// Bind to 'ajaxCart.afterCartLoad' to run any javascript after the cart has loaded in the DOM
timber.RightDrawer.open();
});
//Something I have tried...
$(window).on('scroll', function() {
// when timer is triggered:
timber.rightDrawer.close();
});
</script>
{% endif %}
Any help would be really appreciated!