Javascript 如何检测mouseout是否为真?
我有一个简单的小提琴作为工作的例子- 我试图从Javascript 如何检测mouseout是否为真?,javascript,jquery,setinterval,Javascript,Jquery,Setinterval,我有一个简单的小提琴作为工作的例子- 我试图从div部分检测mouseout事件。 当我将鼠标移到这张图片上时,它会显示标题;说“改变形象”。5秒后,字幕消失 我正在使用setInterval进行相应的设置。现在,若我对这个图像执行mouseout,那个么只需要调用Interval函数 如何在jQuery中检测mouseout事件 尝试过- $(function () { $('.image-profile').mouseover(function () {
div
部分检测mouseout事件。
当我将鼠标移到这张图片上时,它会显示标题;说“改变形象”。5秒后,字幕消失
我正在使用setInterval
进行相应的设置。现在,若我对这个图像执行mouseout,那个么只需要调用Interval函数
如何在jQuery中检测mouseout事件
尝试过-
$(function () {
$('.image-profile').mouseover(function () {
$('.change-image').stop().show();
if ($('.image-profile').mouseout()== true) {
TimeOut();
}
});
setInterval(function TimeOut() {
$('.change-image').fadeOut()
}, 5000
);
});
使用setTimeout和clearTimeout
演示:
现在,div在鼠标进入时显示,在鼠标离开后5秒消失
$(function () {
$('.image-profile').mouseenter(function () {
$('.change-image').stop().show();
});
$('.image-profile').mouseleave(function () {
setTimeout(function TimeOut() {
$('.change-image').fadeOut()
}, 5000);
});
});
试试这个:
(function () {
$('.image-profile').mouseover(function () {
$('.change-image').stop().show();
if ($('.image-profile').mouseout() == true) {
TimeOut();
}
}).mouseout(function () {
setInterval(function TimeOut() {
$('.change-image').fadeOut()
}, 5000);
});
});
您已经使用了
mouseover
,为什么mouseout
会起到任何不同的作用?+我打赌您不想为此使用setInterval()。请尝试setTimeout()
。@Yoshi,仅仅因为我想检测mouseout事件,使用它是另一种方法。@Manoz我想这只是你方面的一个简单误解。由于异步性质,处理事件总是涉及回调函数。您可以隐藏它们或以其他方式抽象它们,但最终将调用一个函数来处理该事件。@Manoz在处理mouseover
时,不能为同一元素触发mouseout事件。鼠标刚刚进入一个元素,如何能够同时检测到该元素的鼠标出?是否可以不使用mouseleave的另一个功能来完成?我想检测mouseout是否为真。是的,你可以@Manoz这样做,只要将mouseleave改为mouseout即可+
$(function () {
$('.image-profile').mouseenter(function () {
$('.change-image').stop().show();
});
$('.image-profile').mouseleave(function () {
setTimeout(function TimeOut() {
$('.change-image').fadeOut()
}, 5000);
});
});
(function () {
$('.image-profile').mouseover(function () {
$('.change-image').stop().show();
if ($('.image-profile').mouseout() == true) {
TimeOut();
}
}).mouseout(function () {
setInterval(function TimeOut() {
$('.change-image').fadeOut()
}, 5000);
});
});