【发布时间】:2012-05-02 20:14:34
【问题描述】:
不知道该怎么做,但基本上我写了一个工具提示插件,它删除了mouseout 或mousedown 上的工具提示。
如果触发了mousedown 事件,它将删除$that.parent(),这很好,这会删除工具提示,但是如果用户还触发了 mouseout 事件(他们会因为 mouseover 和 @ 987654326@ 事件当前被链接),然后它将删除另一个我不想要的 DOM 元素。所以基本上我想知道这是否可能:
$that.on('mouseover', function() {
// If this event is triggered within the mouseover event, don't run the chained mouseout event
$that.on('mousedown', function() {
$that.parent().next().fadeOut(100).remove();
return false;
});
}).mouseout(function() {
// If they clicked above, don't run this
$that.parent().next().fadeOut(100).remove();
});
据我所知,如果不使用全局变量,很难访问 clicked 事件中的 clicked 布尔集,例如:
$that.on('mouseover', function() {
clicked = false;
// If this event is triggered within the mouseover event, don't run the chained mouseout event
$that.on('mousedown', function() {
clicked = true;
$that.parent().next().fadeOut(100).remove();
return false;
});
}).mouseout(function() {
// If they clicked above, don't run this
if (clicked) {
$that.parent().next().fadeOut(100).remove();
}
});
关于如何优雅地构建它有什么想法吗?
编辑:$that.parent().next() 中的元素只是 <div class="js-tooltip"><span>Tooltip text</span></div>
但这应该无关紧要,因为我只想知道如果在不使用全局变量的情况下触发了 mousedown,是否可以从该 mouseover 函数返回。
【问题讨论】:
-
您应该更好地解释一下确切指向哪些元素:
$that.parent().next().fadeOut(100).remove();我的意思是:$that是什么,什么元素是:parent,谁是:.next()?你说 $that.parent() 删除了工具提示,但.next()的目的是什么??? -
@RokoC.Buljan
$that.parent().next()是在被点击的当前元素之后被克隆并插入到 DOM 中的工具提示。$that在这种情况下指的是一个名为 Cancel 的输入按钮,它添加了带有一些文本的工具提示:“Discard Changes”
标签: javascript jquery mouseover jquery-events mousedown