你可以在 onmousexxx 触发的函数加一个 alert 你会发现:在菜单内移动也会触发~ 这是由于 JS 事件冒泡造成的~ 给你一个思路~
在 onmousexxx 函数前都加一个判断:判断现在的层是否位于菜单下面,如果是就退出,这样就能避免闪动问题~
在 onmousexxx 函数前都加一个判断:判断现在的层是否位于菜单下面,如果是就退出,这样就能避免闪动问题~
解决方案 »
- 100分!js 动态添加表格行 排列name属性 重新发贴
- 关于widget.openURL
- 大家看看,我在文件中加入这个移动图片的代码后,网页的文字就不能选中了.我想可选怎么办.
- 怎么在网页里随机图片
- 关于用DIV模拟Confirm确认窗口的问题
- window.open怎样弹出这样的新窗口??? 续集II
- 不用循环如何获取FORM中input:text元素的索引号???
- 怎样构建基于windows2000的bbs服务器?
- 求助帖 关于“无法获取未定义或 null 引用的属性“charCodeAt””
- js如何实现多个相同的form列表提交
- 谁有google map里面的手型鼠标指针图片? 发给我,谢谢。
- 求一个漂亮简单的登录页面
<div id="Layer2" style="FILTER: alpha(opacity=0)" onmouseout="low(this)">
这段代码上,我把鼠标移动在这个层上很容易触发onmouseout事件
这是为什么
position:absolute;
left:158px;
top:185px;
width:60px;
height:60px;
z-index:1;
border-style:Double;
border-color:#993300;
border:3px;
}
#Layer2 {
position:absolute;
left:316px;
top:190px;
width:60px;
height:60px;
z-index:auto;
border-style:Double;
border-color:#993300;
border:3px;
}
这几个层都不会叠层放置,应该不存在上层和下层吧
1.原代码基本没有考虑ie之外的浏览器。多处加 document.all 区分ie 浏览器和标准浏览器。2.Lay.style.left = event.x-event.offsetX+72 这一行无用已经注释。initLayer() showLayer() obj参数无用,已经去掉3.border-style:Double; 不是标准,换掉了。4.过程中,对隐藏单位设置 style.display = 'none' 可以解决很多麻烦。5.clearInterval(lowing), clearInterval(highing)增加多处。6.对Layer1 Layer2 增加onmouseover="initLayer()"7.原 initLayer 里的循环没有判断是否存在对象。这个会报js错误的,现已修改。8.建议gif图换成了jpg图。这个不是大问题。如果你用会动的gif,则每次gif动都会触发onmouseover事件。#Layer1 {
position:absolute;
left:158px;
top:185px;
width:60px;
height:60px;
z-index:1;
border:1px solid #f00;
}
#Layer2 {
position:absolute;
left:316px;
top:190px;
width:60px;
height:60px;
z-index:auto;
border:1px solid #f00;
}function changeimg(obj,num){
//initLayer(num);
var nums;
nums=getnums(num);
//鼠标移动上来替换提片
obj.src="images/banner2_"+nums+".gif";
//初始化子菜单
initLayer(num);
}//还原原图
function recover(obj,num){
var nums;
nums=getnums(num);
obj.src="images/banner_"+nums+".gif";
}//计算图片名称
function getnums(num){
var nums
nums=num*2+1;
if (nums<10){nums="0"+nums}
return nums;
}//初始化子菜单
function initLayer(num){
if (window.highing) clearInterval(highing);
var i=1;
while (i<5){
if (num!=i){
//如果子菜单不属于触发图片则隐藏
if(document.getElementById("Layer"+i)){
hideLayer(document.getElementById("Layer"+i))
}
}
else{
//否则显示子菜单
if(document.getElementById("Layer"+i)){
showLayer(document.getElementById("Layer"+i))
}
}
i++;
}
//high(document.getElementById("Layer"+num));
}//隐藏子菜单
function hideLayer(Lay){
if(document.all){
Lay.filters.alpha.opacity=0;
}else{
Lay.style.opacity = 0;
}
Lay.style.display = 'none'
}//显示子菜单
function showLayer(Lay){
//Lay.style.left = event.x-event.offsetX+72 + 'px'
high(Lay);
}//渐变显示子菜单
function high(imgobj){
if (window.lowing) clearInterval(lowing);
theobject=imgobj;
imgobj.style.display = '';
highing=setInterval("highit(theobject)",10);
}//渐变隐藏子菜单
function low(imgobj){
if (window.highing) clearInterval(highing);
theobject=imgobj;
lowing=setInterval("lowit(theobject)",10);
} //高亮代码
function highit(pic){
if (window.lowing) clearInterval(lowing);
if(document.all){
if (pic.filters.alpha.opacity<100)
pic.filters.alpha.opacity+=5;
else if (window.highing){
window.clearInterval(highing);
}
}else{
if (pic.style.opacity<1){
pic.style.opacity = parseFloat(pic.style.opacity) + 0.05;
}
else if (window.highing)
window.clearInterval(highing);
}
}
function lowit(pic){
if (window.highing) clearInterval(highing);
if(document.all){
if (pic.filters.alpha.opacity>0){
pic.filters.alpha.opacity-=5;
}else if (window.lowing){
window.clearInterval(lowing);
pic.style.display = 'none'
}
}else{
if (pic.style.opacity>0)
pic.style.opacity = parseFloat(pic.style.opacity) - .05;
else if (window.lowing){
window.clearInterval(lowing);
pic.style.display = 'none'
}
}
}<div id="Layer1" style="FILTER: alpha(opacity=0);opacity:0;display:none;" onmouseover="initLayer(1)"onmouseout="low(this)">
<table width="100%" height="60" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="whitetext"><span class="c2">123</span></td>
</tr>
</table>
</div>
<div id="Layer2" style="FILTER: alpha(opacity=0);opacity:0;display:none;" onmouseover="initLayer(2)" onmouseout="low(this)">
<table width="100%" height="60" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="whitetext"><span class="c2">234</span></td>
</tr>
</table>
</div>
<img src="images/banner_03.gif" width="90" height="97" alt="" onmouseover="changeimg(this,1)" onmouseout="recover(this,1)">
<img src="images/banner_05.gif" width="90" height="97" alt="" onmouseover="changeimg(this,2)" onmouseout="recover(this,2)">