jQuery | on click fade out and / or automatically fade out

有些话、适合烂在心里 提交于 2019-12-12 04:57:13

问题


Why is the following code not working? only the delayed fade out is working. Not the click event. If i comment the auto-fade out the click event is working. And how could i shorten the code?

Thanks for your help! :)

var wooMessage = $('.woocommerce-message'); 
var wooError = $('.woocommerce-error'); 

wooMessage.delay(9000).fadeOut(160);
wooError.delay(9000).fadeOut(160);

$('.woocommerce-message-close').click(function() {
    wooMessage.fadeOut(160);
});
$('.woocommerce-error-close').click(function() {
    wooError.fadeOut(160);
}); 

回答1:


ok got it after created my own jsfiddle for it - u "blocking" the woo-elements with the delay so there is already a animation going on u need to stop them first...then its working with the click

var wooMessage = $('.woocommerce-message'); 
var wooError = $('.woocommerce-error'); 

wooMessage.delay(9000).fadeOut(160);
wooError.delay(9000).fadeOut(160);

$('.woocommerce-message-close').click(function() {
    wooMessage.stop().fadeOut(160);
});
$('.woocommerce-error-close').click(function() {
    wooError.stop().fadeOut(160);
}); 


来源:https://stackoverflow.com/questions/27115613/jquery-on-click-fade-out-and-or-automatically-fade-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!