我想设置我的Ajax快速购物车,以便如果用户在快速购物车上徘徊(换句话说与它互动),它会延迟我设置的setInterval,以便一旦某件物品已关闭3秒后添加。在Ajax Quick Cart悬停时暂停setInterval,并在没有时恢复?
我不是那么棒,所以任何帮助将不胜感激!
这是我的原代码:
{% 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();
});
jQuery('body').on('click','#AddToCart', function(evt, cart) {
timber.RightDrawer.open();
var myVar = setInterval(function(){
timber.RightDrawer.close();
clearInterval(myVar);
}, 3000);
});
这是原来的代码,我努力去适应设法得到它的工作,但仍然没有运气,它只是打破我的setInterval的一部分:
jQuery('body').on('click','#AddToCart', function(evt, cart) {
timber.RightDrawer.open();
$('#CartContainer').hover(function(ev){
clearInterval(myVar);
}, function(ev){
myVar = setInterval(function(){
timber.RightDrawer.close();
clearInterval(myVar);
}, 3000);
});
});
没有答案:但你要使用的mouseenter和鼠标离开。 – epascarello
在这里检查一个很好的解决方案http://stackoverflow.com/questions/10913703/adding-pause-on-hover-to-setinterval – AboutTime
我已经更新了我的问题与我刚刚看过你的例子后尝试,但可以'吨似乎得到它的工作,而不会打破我的setInterval。有什么建议么? – user2498890