admin管理员组文章数量:1287613
I use this tab view that developed base on jQuery:
.html#
I change the code that tabs change by mouseenter
event. and I want to delay execution of the mouseenter
event so if mouse enter the elemnt and remain there for portion of time mouseenter
executes else (if mouse go outside in time less that that portion of time) mouseenter
does not execute.I write this code:
$(document).ready(function () {
$('a.tab').on('mouseenter', function () {
var thisElement = $(this);
setTimeout(function () {
$(".active").removeClass("active");
thisElement.addClass("active");
$(".content").slideUp();
var content_show = thisElement.attr("title");
$("#" + content_show).slideDown();
}, 300);
});
});
but if I bring mouse out of element mouseenter
excecutes.How to solve this problem?
thanks
I use this tab view that developed base on jQuery:
https://d2o0t5hpnwv4c1.cloudfront/001_Tabbed/site/jQuery.html#
I change the code that tabs change by mouseenter
event. and I want to delay execution of the mouseenter
event so if mouse enter the elemnt and remain there for portion of time mouseenter
executes else (if mouse go outside in time less that that portion of time) mouseenter
does not execute.I write this code:
$(document).ready(function () {
$('a.tab').on('mouseenter', function () {
var thisElement = $(this);
setTimeout(function () {
$(".active").removeClass("active");
thisElement.addClass("active");
$(".content").slideUp();
var content_show = thisElement.attr("title");
$("#" + content_show).slideDown();
}, 300);
});
});
but if I bring mouse out of element mouseenter
excecutes.How to solve this problem?
thanks
Share Improve this question asked Apr 10, 2012 at 7:32 DooDooDooDoo 13.5k70 gold badges190 silver badges317 bronze badges1 Answer
Reset to default 13You need to store the timeout handle and cancel it on mouseleave
:
var timeout;
$(document).ready(function () {
$('a.tab').on('mouseenter', function () {
var thisElement = $(this);
if (timeout != null) { clearTimeout(timeout); }
timeout = setTimeout(function () {
$(".active").removeClass("active");
thisElement.addClass("active");
$(".content").slideUp();
var content_show = thisElement.attr("title");
$("#" + content_show).slideDown();
}, 300);
});
$('a.tab').on('mouseleave', function () {
if (timeout != null) {
clearTimeout(timeout);
timeout = null;
}
});
});
本文标签: javascriptdelay mouseenter event and raise event if mouse inside the elementStack Overflow
版权声明:本文标题:javascript - delay mouseenter event and raise event if mouse inside the element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741256413a2366759.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论