jQuery:无法淡出以前淡入的元素 [英] jQuery: Unable to fade out a previously faded in element
本文介绍了jQuery:无法淡出以前淡入的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在顶部显示通知-2秒钟-告诉我jQuery&哪个版本jQuery UI已加载.不幸的是,我似乎以后无法将其隐藏.
I want to show a notification at the top – for 2 seconds – telling me which version of jQuery & jQuery UI was loaded. Unfortunately, I can't seem to be able to hide it later.
我的代码
$('<div>jQuery v' + jQuery.fn.jquery + ' and jQuery UI v' + jQuery.ui.version + ' loaded.</div>')
.addClass('ui-state-highlight').prependTo('body').hide(0, function() {
$(this).fadeIn(500, function() {
setTimeout(function() {
$(this).fadeOut(500, function() {
$(this).remove();
});
}, 2000);
});
});
jQuery Lint说我做错了-是的,但是我不知道如何正确做事.
jQuery Lint says I'm doing something wrong – which is true –, but I don't know how to do it the right way.
推荐答案
这可能是范围问题.试试:
It is probably a scope problem. Try:
$(this).fadeIn(500, function() {
var parentContext = $(this);
setTimeout(function() {
parentContext.fadeOut(500, function() {
$(this).remove();
});
}, 2000);
});
这篇关于jQuery:无法淡出以前淡入的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文