您好,我的代码有问题我想做同样的事情,但使用 12 的倍数而不是数字 12
例如 12 杯啤酒、24 杯啤酒等,但不包括 13、14 或 15 杯啤酒。
抱歉,我的英语很不好。
https://bcambre-eshop.webflow.io/test
谢谢
<script>
// Initialize texts
$(".beer-info").hide();
$(".beer-info-alt").hide();
$(".checkout-abs").hide();
// select the target node — here : .cart-list
var target = document.getElementById('target');
// input here your reference value
var targetQty = 12;
// create an observer instance
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
//console.log('cart update');
setTimeout(function(){
var currentQty = $('.w-commerce-commercecartopenlinkcount').text();
var leftQty = targetQty - currentQty ;
// update counter — console.log('cans missing' + ' ' + leftQty);
if ( leftQty <= 0 ) {
$(".beers-left").text(leftQty);
$(".beer-info").hide();
$(".beer-info-alt").show();
$(".checkout-abs").show();
}
else {
$(".beer-info-alt").hide();
$(".checkout-abs").hide();
$(".beer-info").show();
$(".beers-left").text(leftQty);
}
// update progression stackbar — console.log(progressBar);
var progressBar = currentQty / targetQty * 100;
$(".completed-bar").css('width', progressBar + '%');
}, 300);
});
});
// configuration of the observer:
var config = {
attributes: false,
childList: true,
characterData: false
};
// pass in the target node, as well as the observer options
observer.observe(target, config);
</script>