Javascript 退色后移除元件
在插件上,我有以下内容:Javascript 退色后移除元件,javascript,jquery,Javascript,Jquery,在插件上,我有以下内容: var defaults = { hide: function ($element, $tooltip) { $tooltip.fadeOut(4000); } }; $(this).each(function (e) { $this.mouseleave(function (e) { tooltip.timer = setTimeout(function () { options.hide
var defaults = {
hide: function ($element, $tooltip) {
$tooltip.fadeOut(4000);
}
};
$(this).each(function (e) {
$this.mouseleave(function (e) {
tooltip.timer = setTimeout(function () {
options.hide($this, $("." + options.class).stop(true, true), function () {
$("." + options.class).remove(); // THE ELEMENT IS NOT BEING REMOVED
});
}, 0);
}), // Mouse leave
})
在鼠标离开时,我试图在动画结束后删除该元素
问题是没有移除该元素。但如果我使用:
$this.mouseleave(function (e) {
tooltip.timer = setTimeout(function () {
options.hide($this, $("." + options.class).stop(true, true));
$("." + options.class).remove(); // THE ELEMENT IS BEING REMOVED
}, 0);
}), // Mouse leave
然后一切都很好。。。为什么函数(){…}会禁用删除操作?您不能以这种方式传递第三个参数(回调)。试试这个:
var defaults = {
hide: function ($element, $tooltip, $func) {
if(typeof $func === 'function');
$tooltip.fadeOut(4000, 'swing', $func);
else
$tooltip.fadeOut(4000);
}
};
$(this).each(function (e) {
$this.mouseleave(function (e) {
tooltip.timer = setTimeout(function () {
options.hide($this, $("." + options.class).stop(true, true), function () {
$("." + options.class).remove(); // THE ELEMENT IS NOT BEING REMOVED
});
}, 0);
}), // Mouse leave
})
编辑:
JSFIDLE上的演示:您不能以这种方式传递第三个参数(回调)。试试这个:
var defaults = {
hide: function ($element, $tooltip, $func) {
if(typeof $func === 'function');
$tooltip.fadeOut(4000, 'swing', $func);
else
$tooltip.fadeOut(4000);
}
};
$(this).each(function (e) {
$this.mouseleave(function (e) {
tooltip.timer = setTimeout(function () {
options.hide($this, $("." + options.class).stop(true, true), function () {
$("." + options.class).remove(); // THE ELEMENT IS NOT BEING REMOVED
});
}, 0);
}), // Mouse leave
})
编辑:
jsidle上的演示:我想你指的是不同的
这个
,一个是$(这个)
,到目前为止它没有提到任何元素,然后你在$(这个)里面有$this
,each()
,谁是$(这个)?,我想你的元素需要另一个选择器,比如$('.className')。然后在内部,您可以对具有相同类名的每个元素使用$(this):
$('.myClass').each(function (e) {
$(this).mouseleave(function (e) {
tooltip.timer = setTimeout(function () {
options.hide($this, $("." + options.class).stop(true, true), function () {
$("." + options.class).remove();
});
}, 0);
}),
})
也许您可以使用Jquery hover:
$(this).hover(function(){
//on mouse over
}, function(){
//on mouse out
$(the_elm_toRemove).remove();
});
我想你指的是不同的
this
,一个是$(this)
,到目前为止它没有引用任何元素,然后你在$(this)里面有$this
。each()
,谁是$(this)??,我想你的元素需要另一个选择器,比如$('.className')。然后在内部,您可以对具有相同类名的每个元素使用$(this):
$('.myClass').each(function (e) {
$(this).mouseleave(function (e) {
tooltip.timer = setTimeout(function () {
options.hide($this, $("." + options.class).stop(true, true), function () {
$("." + options.class).remove();
});
}, 0);
}),
})
也许您可以使用Jquery hover:
$(this).hover(function(){
//on mouse over
}, function(){
//on mouse out
$(the_elm_toRemove).remove();
});
如果你这样做-
$(this)。mouseleave(函数(e){
,它不能解决问题…我有一个在线示例:…我所拥有的似乎是逻辑的,但它是如何工作的。你知道我缺少了什么吗?@wirey他正在使用。隐藏(持续时间[,放松][,完成])
我之所以在默认设置中使用隐藏功能,是因为我想允许使用工具提示的用户使用自定义动画来显示或隐藏。如果您这样做-$(this)。mouseleave(函数(e){
这并不能解决问题…我有一个在线示例:…我所拥有的似乎是逻辑的,但它是如何工作的。知道我缺少什么吗?@wirey他正在使用.hide(持续时间[,放松][,完成])
我之所以在默认设置中使用隐藏函数,是因为我想允许使用工具提示的用户使用自定义动画来显示或隐藏。这并不能解决问题……我在中添加了示例,改进了我的答案,并在JSFIDLE上做了一些测试(CodePen没有给我留下深刻印象)。我确信它达到了$(“+options.class.).remove()
行。这并不能解决问题…我在中添加了这个示例,改进了我的答案,并在JSFIDLE上做了一些测试(CodePen没有给我留下深刻印象)。我确信它达到了$(“+options.class).remove();
行。我正在使用$this缓存$(this)。请检查我的在线示例,哦,我明白了,你考虑过悬停吗?看看我的答案我添加了一些新代码,可能会有帮助:)我正在使用$this缓存$(这个)。请检查我的在线示例,哦,我明白了,你考虑过悬停吗?看看我的答案我添加了一些新代码,可能会有帮助:)