我使用这个jQuery来添加购物车弹出菜单,但无法解决如何添加5秒的超时.
(function($) {
"use strict";
jQuery(document).mouseup(function (e) {
container = jQuery('.atc-notice-wrapper');
if (!container.is(e.target) && container.has(e.target).length === 0 ) {
jQuery('.atc-notice-wrapper').fadeOut();
}
});
jQuery(document).ready(function(){
jQuery('body').append('<div class="atc-notice-wrapper"><div class="atc-notice"></div><div class="close"><i class="fa fa-times-circle"></i></div></div>');
jQuery('.atc-notice-wrapper .close').on('click', function(){
jQuery('.atc-notice-wrapper').fadeOut();
jQuery('.atc-notice').html('');
});
var ajaxPId = 0;
jQuery('body').on( 'adding_to_cart', function(event, button, data) {
ajaxPId = button.attr('data-product_id');
});
jQuery('body').on( 'added_to_cart', function(event, fragments, cart_hash) {
//get product info by ajax
jQuery.post(
ajaxurl,
{
'action': 'get_productinfo',
'data': {'pid': ajaxPId}
},
function(response){
jQuery('.atc-notice').html(response);
//show product info after added
jQuery('.atc-notice-wrapper').fadeIn();
}
);
});
jQuery('body').on( 'added_to_cart', function(event, fragments, cart_hash) {
//show product info after added
jQuery('.atc-notice-wrapper').fadeIn();
});
function hideQuickView(){
jQuery('.quickview-wrapper').removeClass('open');
window.setTimeout(function(){
jQuery('body').removeClass('quickview');
}, 500);
}
} );
})( window.jQuery );
我想我需要添加以下内容:
setTimeout(function(){
$('.atc-notice-wrapper').modal('hide')
}, 5000);
此外,我还想知道是否可以通过子主题添加超时,而无需编辑默认的jQuery.