- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已使用 Timber framework 成功设置了 Shopify Ajax 购物车因此,目前如果您单击购物车外部的任何位置(或使用关闭按钮),我的购物车就会关闭。
我希望能够创建一个计时器,以便在将产品添加到购物车后,ajax 快速购物车打开它,然后在 5 秒后关闭,以便用户可以继续购物。如果他们想更长时间地查看购物车,可以点击购物车按钮重新打开,然后单击完整购物车页面的链接。
有人建议我可以用 wood.RightDrawer.close(); 关闭购物车。我应该在像下面这样的监听器中设置它,但是作为 JS 新手,我正在努力不知道从哪里开始。
jQuery('body').on('ajaxCart.afterCartLoad', function(evt, cart) {
// start timer function
// when timer is triggered:
timber.rightDrawer.close();
});
我已经尝试过以下方法,但我真的只是猜测......
jQuery('body').on('ajaxCart.afterCartLoad', function(evt, cart) {
// start timer function
$('#AddToCart').on('click', function(){
setTimeout(function(){
// when timer is triggered:
timber.rightDrawer.close();
},500);
});
});
我当前的一些代码如下,请参阅 Timber 框架以进行与我相同的设置:
主题.liquid JS:
{% 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();
});
</script>
{% endif %}
timber.js.liquid:
timber.drawersInit = function () {
timber.LeftDrawer = new timber.Drawers('NavDrawer', 'left');
timber.RightDrawer = new timber.Drawers('CartDrawer', 'right',
'onDrawerOpen': ajaxCart.load
});
};
timber.Drawers = (function () {
var Drawer = function (id, position, options) {
var defaults = {
close: '.js-drawer-close',
open: '.js-drawer-open-' + position,
openClass: 'js-drawer-open',
dirOpenClass: 'js-drawer-open-' + position
};
this.$nodes = {
parent: $('body, html'),
page: $('#PageContainer'),
moved: $('.is-moved-by-drawer')
};
this.config = $.extend(defaults, options);
this.position = position;
this.$drawer = $('#' + id);
if (!this.$drawer.length) {
return false;
}
this.drawerIsOpen = false;
this.init();
};
Drawer.prototype.init = function () {
$(this.config.open).on('click', $.proxy(this.open, this));
this.$drawer.find(this.config.close).on('click', $.proxy(this.close, this));
};
Drawer.prototype.open = function (evt) {
// Keep track if drawer was opened from a click, or called by another function
var externalCall = false;
// Prevent following href if link is clicked
if (evt) {
evt.preventDefault();
} else {
externalCall = true;
}
// Without this, the drawer opens, the click event bubbles up to $nodes.page
// which closes the drawer.
if (evt && evt.stopPropagation) {
evt.stopPropagation();
// save the source of the click, we'll focus to this on close
this.$activeSource = $(evt.currentTarget);
}
if (this.drawerIsOpen && !externalCall) {
return this.close();
}
// Add is-transitioning class to moved elements on open so drawer can have
// transition for close animation
this.$nodes.moved.addClass('is-transitioning');
this.$drawer.prepareTransition();
this.$nodes.parent.addClass(this.config.openClass + ' ' + this.config.dirOpenClass);
this.drawerIsOpen = true;
// Run function when draw opens if set
if (this.config.onDrawerOpen && typeof(this.config.onDrawerOpen) == 'function') {
if (!externalCall) {
this.config.onDrawerOpen();
}
}
if (this.$activeSource && this.$activeSource.attr('aria-expanded')) {
this.$activeSource.attr('aria-expanded', 'true');
}
// Lock scrolling on mobile
this.$nodes.page.on('touchmove.drawer', function () {
return false;
});
this.$nodes.page.on('click.drawer', $.proxy(function () {
this.close();
return false;
}, this));
};
Drawer.prototype.close = function () {
if (!this.drawerIsOpen) { // don't close a closed drawer
return;
}
// deselect any focused form elements
$(document.activeElement).trigger('blur');
// Ensure closing transition is applied to moved elements, like the nav
this.$nodes.moved.prepareTransition({ disableExisting: true });
this.$drawer.prepareTransition({ disableExisting: true });
this.$nodes.parent.removeClass(this.config.dirOpenClass + ' ' + this.config.openClass);
this.drawerIsOpen = false;
this.$nodes.page.off('.drawer');
};
return Drawer;
})();
// Initialize Timber's JS on docready
$(timber.init);
最佳答案
使用setinterval设置时间为5s
jQuery('body').on('click','#AddToCart', function(evt, cart) {
timber.RightDrawer.open();
var myVar = setInterval(function(){
timber.RightDrawer.close();
clearInterval(myVar);
}, 5000);
});
关于javascript - 添加计时器以在将产品添加到购物车后关闭 Ajax Quick Cart (Shopify)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29697082/
到目前为止,基本上我的脚本将值发送到网关,然后被重定向到 CS 购物车。在该页面中,我获取返回的值并对其进行操作。 我使用 fn finish 和 fn 更改订单状态来完成订单,但无论我做什么,我都会
到目前为止,基本上我的脚本将值发送到网关,然后被重定向到 CS 购物车。在该页面中,我获取返回的值并对其进行操作。 我使用 fn finish 和 fn 更改订单状态来完成订单,但无论我做什么,我都会
我创建了一个上下文处理器,通过在购物车应用程序目录中创建一个新文件并将其命名为 context_processors.py,将当前购物车设置为模板的请求上下文: from .cart import C
我网页顶部的购物车 block 和每个产品中的“添加到购物车”按钮都消失了。这种情况发生在我网站的每个页面上,而且是突然发生的(请原谅,如果我能记忆起/缩小我所做的更改是导致这种情况的原因,那么我就不
我正在尝试在 Shopify 中制作一个 ajaxed 购物车。我已使产品页面将商品添加到购物车,而无需刷新或转到购物车页面。要查看购物车,您可以单击输入或带有 .cart-show 的链接,因此我将
我试图弄清楚如何将 css 类添加到 SimpleCartJS 的购物车表中生成。 (我使用的购物车布局是这样的: http://bootsnipp.com/snippets/featured/sho
我有一个函数add_to_cart想要反向重定向到由single_product函数呈现的产品详细信息页面,该函数具有产品id的slug,无法找到解决它的方法。正在获取这个错误 Reverse for
有人知道购物车(或类似商品)的Unicode字符吗?我找到了比萨饼(U + 1F355),热线电话(U + 2706)以及这是什么(U + 26A7),但没有该死的购物车! 最佳答案 到目前为止,没有
此代码段为我提供了以下错误消息: def cartItems(cart): items=[] for item in cart: items.append(Produc
我想在 prestashop os-commerce 上获取购物车内容。怎么做到的? 最佳答案 您应该看一下位于 classes/Cart.php 中的 Cart 类。有一个名为 getProduct
我正在使用 Magento 购物者主题 (http://shopper.queldorei.com/)。 当我将产品添加到我的购物车时,它会添加多个元素 Cart 我发现是 jQuery 在这里犯
CS-Cart ajax 工作正常,我也收到响应,但如何在我的 View (checkout.tpl)文件上使用 html/js 响应。 Controller (前端):send_sms.php us
我只在 Magento 上工作了几天,但它已经很令人困惑了。我开始思考这个问题,但目前有一个问题是我的思考。 我的客户想要顶部链接旁边的购物篮功能,而不是顶部链接中的“我的购物车”。简单地说,我想做的
在作业中,我们被要求对 CART 模型执行交叉验证。我试过使用 cvFit函数来自 cvTools但收到一条奇怪的错误消息。这是一个最小的例子: library(rpart) library(cvTo
在主产品信息页面中,它显示了完整的产品描述,我试图放入超长的 HTML 代码来进行打包交易。在编写了大约 1200 行 html 后,我遇到了困难。 我可以做一些改变来扩大产品描述的最大字符长度吗?
我想在 shopify 的 cart.liquid 页面上添加结帐进度条。当用户点击产品上的添加到购物车时,我想显示一个进度条。任何帮助将不胜感激。 最佳答案 只要您的客户离开购物车页面去结账,新的
我在代码中存储多个 ID 时遇到问题。我需要将 id 保存在单个变量(数组)中,因为我将在 cart.php 中调用它来显示添加到购物车的元素。这是我的代码。 Marketech | Bu
我今天工作的服务器的主机在安装 x-cart 后关闭了该站点,因为在服务器上发出了以下命令,他们认为这是一个安全漏洞: ls -la 2>&1 id 2>&1;whoami 2>&1; id 2>&1
您好,我正在尝试创建一个在线电子商务商店,尽管有 paypal 购物车上传功能,但我一切正常,我一直在关注来自 developphp.com 的一系列视频这是我的文件 cart.php 中的代码 a
我有一个 cs-cart 项目,它以我不希望的方式显示页面标题(嗯,以客户不喜欢的方式)。 我希望它显示:在主页上:公司名称在其他页面上:公司名称 |页面标题(即公司名称|关于我们)等 我有以下脚本:
我是一名优秀的程序员,十分优秀!