use*_*104 6 javascript jquery if-statement hover
我想要实现的是当鼠标没有悬停menu3时,系统将继续检查aboutMenu是否悬停,如果是,则警告'h',并警告'nh'其他人.问题是它只在鼠标离开menu3时检查一次,如何解决这个问题?谢谢.
$('#menu3').live('mouseout',function() {
$("#aboutMenu").hover(function() {
$(this).data("hovered", true);
}, function() {
$(this).data("hovered", false);
});
if ( $("#aboutMenu").data("hovered") ) {
alert ('h');
} else {
alert ('nh');
}
});
Run Code Online (Sandbox Code Playgroud)
更新:
或者另一种方法是系统继续检查menu3或aboutMenu是否悬停,如果没有,则会弹出悬停的消息.但是,这只会在页面初始化时运行一次,如何让它继续检查?谢谢
$(document).ready(function() {
$("#aboutMenu,#menu3").hover(function() {
$(this).data("hovered", true);
}, function() {
$(this).data("hovered", false);
});
if ( $("#aboutMenu,#menu3").data("hovered") )
alert ('hovered');
});
Run Code Online (Sandbox Code Playgroud)
function checkHover() {
if ($("#aboutMenu,#menu3").hasClass("hovered")) {
alert ('hovered');
//other stuff if hovered
}
else {
//other stuff if not hovered
}
}
$(document).ready(function() {
$("#aboutMenu,#menu3").hover(function() {
$(this).addClass("hovered");
}, function() {
$(this).removeClass("hovered");
});
setInterval(checkHover, 1000);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3394 次 |
| 最近记录: |