事件触发函数的问题
以下是我的测试代码,我想实现一种功能就是当层div1被onmouseover时展开div2,div1被onmouseout地收缩div2,但当div2被onmouseover时div2不收缩,只有div1或div2被onmouseout时div2才收缩,但div2被onmouseover时已经onmouseout div1了,即div2由于div1被onmouseout而收缩。我想问怎么设计使div2被onmouseover且div1被onmouseout时,层div2不会收缩?有没有朋友能给点tips呢?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
<!--
#div1{position:relative;height:25px;width:60px;background-color:#FFD5AA;}
#div2{position:absolute;top:25px;left:0px;background-color:#B5FFB5;}
-->
</style>
<script type="text/javascript">
<!--
window.onload=function(){
$("div1").onmouseover=function(){
if ($("div2").style.width != "0px") return;
$("div2").style.display = "block";
expand($("div2"),"+",140,"block");
}
$("div1").onmouseout=function(){
if ($("div2").style.width != "140px") return;
expand($("div2"),"-",0,"none");
}
/*$("div2").onmouseover=function(){
if (stop){
clearTimeout(stop);
}
}*/
}
function expand(o,fuhao,wh,dis){
eval("var th = parseInt(o.style.height)"+fuhao+"5");
eval("var tw = parseInt(o.style.width)"+fuhao+"5");
o.style.height = th+"px";
o.style.width = tw+"px";
stop = setTimeout(function(){ expand(o,fuhao,wh,dis) },10);
if (th == wh || tw == wh){
clearTimeout(stop);
o.style.display = dis;
}
}
function $(oid){
return document.getElementById(oid);
}
//-->
</script>
</head>
<body>
<div id="div1">
<div id="div2" style="width:0px;height:0px;display:none;"></div>
</div>
</body>
</html>
...全文
相关推荐
js 触发select onchange事件代码
最后,使用JavaScript代码自动设置select元素的值并触发onchange事件时,要注意兼容性问题。
js onmousewheel事件多次触发问题解决方法
如果在animate动画执行期间又触发了该事件,可能会导致scrollFunc函数递归调用自己,从而引起多次触发。针对问题的解决方案,核心思路是阻止事件的多次触发。具体来说,可以采取以下步骤:1.
让Timer控件每5分钟触发一次事件
**兼容性问题**:确保该解决方案在不同版本的Visual Basic中都能正常工作。#### 四、总结通过上述方法,我们可以轻松地实现让 `Timer` 控件每5分钟触发一次事件的目标。
解决Js先触发失去焦点事件再执行点击事件的问题
在本案例中,通过在blur事件中加入延时处理(使用setTimeout函数),可以解决点击事件被提前触发的问题。
vue vantUI tab切换时 list组件不触发load事件的问题及解决方法
为了解决这个问题,开发者在文档中提出了一个有效的解决方案:在Tab切换时,对List组件进行重新初始化。这可以通过在Tab切换的事件处理函数中添加对List组件状态的重置逻辑来实现。


