jQuery |单击淡出和/或自动淡出 [英] jQuery | on click fade out and / or automatically fade out

查看:105
本文介绍了jQuery |单击淡出和/或自动淡出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么以下代码不起作用?只有延迟的淡出才有效.不是点击事件.如果我发表评论,则点击事件会自动消失.而且我该如何缩短代码?

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);
}); 

推荐答案

为此创建了自己的jsfiddle之后,就可以了-u延迟阻塞"低音元素,所以已经有动画在播放了,您需要首先停止它们...然后通过点击进行操作

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);
}); 

这篇关于jQuery |单击淡出和/或自动淡出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆