js冲突的问题 菜单下拉列表的js和幻灯片的js冲突。幻灯片显示的地方下拉列表被隐藏在幻灯片下,该怎么让菜单下拉列表始终显示在最前面呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这是菜单的div:<div class="top3"><ul id="sddm"> <li class="li1"><a href="#" onmouseover="mopen('m1')" onmouseout="mclosetime()"><span style="font-size:14px; color:#FFFFFF;">首页</span></a> </li> <li class="li2"><a href="#" onmouseover="mopen('m2')" onmouseout="mclosetime()"><span style="font-size:14px; color:#0973c6;">商会简介</span></a> <div id="m2" onmouseover="mcancelclosetime()" onmouseout="mclosetime()"><a href="#" title="">关于我们</a><a href="#" title="">关于我们</a><a href="#" title="">关于我们</a><a href="#" title="">关于我们</a><a href="#" title="">关于我们</a><a href="#" title="">关于我们</a> </div> </li> <li><a href="#" onmouseover="mopen('m3')" onmouseout="mclosetime()"><span style="font-size:14px; color:#0973c6;">信息服务</span></a> <div id="m3" onmouseover="mcancelclosetime()" onmouseout="mclosetime()"><a href="#" title="">基层动态</a> </div> </li> <li><a href="#" onmouseover="mopen('m4')" onmouseout="mclosetime()"><span style="font-size:14px; color:#0973c6;">教育培训</span></a> <div id="m4" onmouseover="mcancelclosetime()" onmouseout="mclosetime()"><a href="#" title="">培训活动</a> </div> </li> <li><a href="#" onmouseover="mopen('m5')" onmouseout="mclosetime()"><span style="font-size:14px; color:#0973c6;">融资服务</span></a> <div id="m5" onmouseover="mcancelclosetime()" onmouseout="mclosetime()"><a href="#">金融政策</a> </div> </li> <li><a href="#" onmouseover="mopen('m6')" onmouseout="mclosetime()"><span style="font-size:14px; color:#0973c6;">法律维权</span></a> <div id="m6" onmouseover="mcancelclosetime()" onmouseout="mclosetime()"><a href="#">政策法规</a> </div> </li> <li><a href="#" onmouseover="mopen('m7')" onmouseout="mclosetime()"><span style="font-size:14px; color:#0973c6;">互助合作</span></a> <div id="m7" onmouseover="mcancelclosetime()" onmouseout="mclosetime()"><a href="#">企业展示</a> </div> </li> <li class="li2"><a href="#" onmouseover="mopen('m8')" onmouseout="mclosetime()"><span style="font-size:14px; color:#0973c6;">对外交流</span></a> <div id="m8" onmouseover="mcancelclosetime()" onmouseout="mclosetime()"><a href="#">经贸考察</a> </div> </li></ul></div>以下是菜单样式:<style>#sddm{ margin:0px; width: 900px; height:27px; }#sddm li{ margin: 0; padding: 0; list-style: none; width:86px; height:27px; line-height:27px; float: left; font: bold 12px arial}#sddm li a{ display: block; background-image:url(images/top_2.gif); width:86px; color: #000000; text-align: center; line-height:27px; text-decoration: none}#sddm li.li1 a{ background-image:url(images/top_1.gif);color:#FFF; }#sddm div{ position: absolute; visibility: hidden; margin: 0; padding: 0; border: 1px solid #5970B2} #sddm div a { position: relative; display: block; margin: 0; padding: 5px; white-space: nowrap; text-align: left; text-decoration: none; background: #EAEBD8; font: 12px arial} #sddm div a:hover { background: #49A3FF; color: #FFF}</style>以下是菜单栏js代码:<script type="text/javascript"><!--var timeout = 500;var closetimer = 0;var ddmenuitem = 0;// open hidden layerfunction mopen(id){ // cancel close timer mcancelclosetime(); // close old layer if(ddmenuitem) ddmenuitem.style.visibility = 'hidden'; // get new layer and show it ddmenuitem = document.getElementById(id); ddmenuitem.style.visibility = 'visible';}// close showed layerfunction mclose(){ if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';}// go close timerfunction mclosetime(){ closetimer = window.setTimeout(mclose, timeout);}// cancel close timerfunction mcancelclosetime(){ if(closetimer) { window.clearTimeout(closetimer); closetimer = null; }}// close layer when click-outdocument.onclick = mclose; // --></script> 以下是幻灯片html: <DIV id=idContainer2 class=container><TABLE id=idSlider2 border=0 cellSpacing=0 cellPadding=0> <TBODY> <TR> <TD class=td_f><a href="http://www.lanrentuku.com/" target="_blank"><img src="images/01.jpg" /></a></TD> <TD class=td_f><A href="http://www.lanrentuku.com/" target="_blank"><IMG src="images/02.jpg"></A></TD> <TD class=td_f><A href="http://www.lanrentuku.com/" target="_blank"><IMG src="images/03.jpg"></A></TD> <TD class=td_f><A href="http://www.lanrentuku.com/" target="_blank"><IMG src="images/04.jpg"></A></TD> <TD class=td_f><A href="http://www.lanrentuku.com/" target="_blank"><IMG src="images/05.jpg"></A></TD> <TD class=td_f><A href="http://www.lanrentuku.com/" target="_blank"><IMG src="images/con_1.jpg"></A></TD> </TR></TBODY></TABLE><UL id=idNum class=num></UL></DIV>以下是幻灯片js:<!-- 幻灯片特效 start--><SCRIPT type=text/javascript>var $ = function (id) { return "string" == typeof id ? document.getElementById(id) : id;};var Extend = function(destination, source) { for (var property in source) { destination[property] = source[property]; } return destination;}var CurrentStyle = function(element){ return element.currentStyle || document.defaultView.getComputedStyle(element, null);}var Bind = function(object, fun) { var args = Array.prototype.slice.call(arguments).slice(2); return function() { return fun.apply(object, args.concat(Array.prototype.slice.call(arguments))); }}var Tween = { Quart: { easeOut: function(t,b,c,d){ return -c * ((t=t/d-1)*t*t*t - 1) + b; } }, Back: { easeOut: function(t,b,c,d,s){ if (s == undefined) s = 1.70158; return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; } }, Bounce: { easeOut: function(t,b,c,d){ if ((t/=d) < (1/2.75)) { return c*(7.5625*t*t) + b; } else if (t < (2/2.75)) { return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; } else if (t < (2.5/2.75)) { return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; } else { return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; } } }}//容器对象,滑动对象,切换数量var SlideTrans = function(container, slider, count, options) { this._slider = $(slider); this._container = $(container);//容器对象 this._timer = null;//定时器 this._count = Math.abs(count);//切换数量 this._target = 0;//目标值 this._t = this._b = this._c = 0;//tween参数 this.Index = 0;//当前索引 this.SetOptions(options); this.Auto = !!this.options.Auto; this.Duration = Math.abs(this.options.Duration); this.Time = Math.abs(this.options.Time); this.Pause = Math.abs(this.options.Pause); this.Tween = this.options.Tween; this.onStart = this.options.onStart; this.onFinish = this.options.onFinish; var bVertical = !!this.options.Vertical; this._css = bVertical ? "top" : "left";//方向 //样式设置 var p = CurrentStyle(this._container).position; p == "relative" || p == "absolute" || (this._container.style.position = "relative"); this._container.style.overflow = "hidden"; this._slider.style.position = "absolute"; this.Change = this.options.Change ? this.options.Change : this._slider[bVertical ? "offsetHeight" : "offsetWidth"] / this._count;};SlideTrans.prototype = { //设置默认属性 SetOptions: function(options) { this.options = {//默认值 Vertical: true,//是否垂直方向(方向不能改) Auto: true,//是否自动 Change: 0,//改变量 Duration: 50,//滑动持续时间 Time: 10,//滑动延时 Pause: 4000,//停顿时间(Auto为true时有效) onStart: function(){},//开始转换时执行 onFinish: function(){},//完成转换时执行 Tween: Tween.Quart.easeOut//tween算子 }; Extend(this.options, options || {}); }, //开始切换 Run: function(index) { //修正index index == undefined && (index = this.Index); index < 0 && (index = this._count - 1) || index >= this._count && (index = 0); //设置参数 this._target = -Math.abs(this.Change) * (this.Index = index); this._t = 0; this._b = parseInt(CurrentStyle(this._slider)[this.options.Vertical ? "top" : "left"]); this._c = this._target - this._b; this.onStart(); this.Move(); }, //移动 Move: function() { clearTimeout(this._timer); //未到达目标继续移动否则进行下一次滑动 if (this._c && this._t < this.Duration) { this.MoveTo(Math.round(this.Tween(this._t++, this._b, this._c, this.Duration))); this._timer = setTimeout(Bind(this, this.Move), this.Time); }else{ this.MoveTo(this._target); this.Auto && (this._timer = setTimeout(Bind(this, this.Next), this.Pause)); } }, //移动到 MoveTo: function(i) { this._slider.style[this._css] = i + "px"; }, //下一个 Next: function() { this.Run(++this.Index); }, //上一个 Previous: function() { this.Run(--this.Index); }, //停止 Stop: function() { clearTimeout(this._timer); this.MoveTo(this._target); }};</SCRIPT><SCRIPT> var forEach = function(array, callback, thisObject){ if(array.forEach){ array.forEach(callback, thisObject); }else{ for (var i = 0, len = array.length; i < len; i++) { callback.call(thisObject, array[i], i, array); } } } var st = new SlideTrans("idContainer2", "idSlider2", 6, { Vertical: false }); var nums = []; //插入数字 for(var i = 0, n = st._count - 1; i <= n;){ (nums[i] = $("idNum").appendChild(document.createElement("li"))).innerHTML = ++i; } forEach(nums, function(o, i){ o.onmouseover = function(){ o.className = "on"; st.Auto = false; st.Run(i); } o.onmouseout = function(){ o.className = ""; st.Auto = true; st.Run(); } }) //设置按钮样式 st.onStart = function(){ forEach(nums, function(o, i){ o.className = st.Index == i ? "on" : ""; }) } st.Run();</SCRIPT>代码全部贴给大家了,可以正常运行,只是幻灯片优先级总是高于菜单的。所以菜单栏有些地方总是被幻灯片遮挡无法显示。求各位大虾帮忙解决呀,谢谢啦^_^ ie中的下拉框一直都有这个问题 建议当幻灯片显示时隐藏下拉框 把所有下拉框定义一个class 把他们都hidden 关闭幻灯片时再显示出来 不能关闭下拉框啊。幻灯片是循环显示的。我就是用div做的啊。只是在网上找的幻灯片代码是table而已。没有什么办法能让菜单栏的优先级高于幻灯片吗? 感觉应该不是JS冲突的问题吧,是不是有一个下拉菜单,然后鼠标移动到上面以后会出现一个下拉菜单,有问题的地方应该是下拉菜单被你的幻灯片遮挡住了吧?貌似应该是层的优先级问题,你应该着手查看CSS样式吧,不应该找JS的问题。 好像是层的优先级的问题。可是网上找的解决方法说在菜单的div层中加一个iframe框架。我加上了也没有效果呢 z-index 可以设置div优先级 幻灯片的设成1000 下拉框的设的低点 论坛图片文字怎么处理 Web GIS 大家帮帮忙,在线等一个问题的解决方法 难啊,请高手帮忙………… 购物网问题?? 大家出出主意!! 大家帮忙看看JAVA中二维数组作为函数的参数应该怎么传递 servlet的小问题,请帮助!! 在<body>里执行一个js函数?怎样做?很简单,马上给分 如何在JSP页面中实现下载统计 请教一个SQL 关于过滤器配置的错误 The Struts dispatcher cannot be found
<div class="top3">
<ul id="sddm"> <li class="li1"><a href="#" onmouseover="mopen('m1')" onmouseout="mclosetime()"><span style="font-size:14px; color:#FFFFFF;">首页</span></a>
</li>
<li class="li2"><a href="#" onmouseover="mopen('m2')" onmouseout="mclosetime()"><span style="font-size:14px; color:#0973c6;">商会简介</span></a>
<div id="m2" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#" title="">关于我们</a>
<a href="#" title="">关于我们</a>
<a href="#" title="">关于我们</a>
<a href="#" title="">关于我们</a>
<a href="#" title="">关于我们</a>
<a href="#" title="">关于我们</a>
</div>
</li>
<li><a href="#" onmouseover="mopen('m3')" onmouseout="mclosetime()"><span style="font-size:14px; color:#0973c6;">信息服务</span></a>
<div id="m3" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#" title="">基层动态</a>
</div>
</li>
<li><a href="#" onmouseover="mopen('m4')" onmouseout="mclosetime()"><span style="font-size:14px; color:#0973c6;">教育培训</span></a>
<div id="m4" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#" title="">培训活动</a> </div>
</li>
<li><a href="#" onmouseover="mopen('m5')" onmouseout="mclosetime()"><span style="font-size:14px; color:#0973c6;">融资服务</span></a>
<div id="m5" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#">金融政策</a> </div>
</li>
<li><a href="#" onmouseover="mopen('m6')" onmouseout="mclosetime()"><span style="font-size:14px; color:#0973c6;">法律维权</span></a>
<div id="m6" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#">政策法规</a> </div>
</li>
<li><a href="#" onmouseover="mopen('m7')" onmouseout="mclosetime()"><span style="font-size:14px; color:#0973c6;">互助合作</span></a>
<div id="m7" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#">企业展示</a> </div>
</li>
<li class="li2"><a href="#" onmouseover="mopen('m8')" onmouseout="mclosetime()"><span style="font-size:14px; color:#0973c6;">对外交流</span></a>
<div id="m8" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#">经贸考察</a> </div>
</li>
</ul>
</div>以下是菜单样式:<style>
#sddm
{ margin:0px;
width: 900px;
height:27px;
}#sddm li
{ margin: 0;
padding: 0;
list-style: none;
width:86px;
height:27px;
line-height:27px;
float: left;
font: bold 12px arial}#sddm li a
{ display: block; background-image:url(images/top_2.gif);
width:86px; color: #000000;
text-align: center;
line-height:27px;
text-decoration: none}
#sddm li.li1 a
{ background-image:url(images/top_1.gif);
color:#FFF;
}
#sddm div
{ position: absolute;
visibility: hidden;
margin: 0;
padding: 0;
border: 1px solid #5970B2} #sddm div a
{ position: relative;
display: block;
margin: 0;
padding: 5px;
white-space: nowrap;
text-align: left;
text-decoration: none;
background: #EAEBD8; font: 12px arial} #sddm div a:hover
{ background: #49A3FF;
color: #FFF}
</style>以下是菜单栏js代码:<script type="text/javascript">
<!--
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;// open hidden layer
function mopen(id)
{
// cancel close timer
mcancelclosetime(); // close old layer
if(ddmenuitem) ddmenuitem.style.visibility = 'hidden'; // get new layer and show it
ddmenuitem = document.getElementById(id);
ddmenuitem.style.visibility = 'visible';}
// close showed layer
function mclose()
{
if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}// go close timer
function mclosetime()
{
closetimer = window.setTimeout(mclose, timeout);
}// cancel close timer
function mcancelclosetime()
{
if(closetimer)
{
window.clearTimeout(closetimer);
closetimer = null;
}
}// close layer when click-out
document.onclick = mclose;
// -->
</script>
<TABLE id=idSlider2 border=0 cellSpacing=0 cellPadding=0>
<TBODY>
<TR>
<TD class=td_f><a href="http://www.lanrentuku.com/" target="_blank"><img src="images/01.jpg" /></a></TD>
<TD class=td_f><A href="http://www.lanrentuku.com/" target="_blank"><IMG src="images/02.jpg"></A></TD>
<TD class=td_f><A href="http://www.lanrentuku.com/" target="_blank"><IMG src="images/03.jpg"></A></TD>
<TD class=td_f><A href="http://www.lanrentuku.com/" target="_blank"><IMG src="images/04.jpg"></A></TD>
<TD class=td_f><A href="http://www.lanrentuku.com/" target="_blank"><IMG src="images/05.jpg"></A></TD>
<TD class=td_f><A href="http://www.lanrentuku.com/" target="_blank"><IMG src="images/con_1.jpg"></A></TD>
</TR></TBODY></TABLE>
<UL id=idNum class=num></UL>
</DIV>以下是幻灯片js:<!-- 幻灯片特效 start-->
<SCRIPT type=text/javascript>
var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};var Extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}var CurrentStyle = function(element){
return element.currentStyle || document.defaultView.getComputedStyle(element, null);
}var Bind = function(object, fun) {
var args = Array.prototype.slice.call(arguments).slice(2);
return function() {
return fun.apply(object, args.concat(Array.prototype.slice.call(arguments)));
}
}var Tween = {
Quart: {
easeOut: function(t,b,c,d){
return -c * ((t=t/d-1)*t*t*t - 1) + b;
}
},
Back: {
easeOut: function(t,b,c,d,s){
if (s == undefined) s = 1.70158;
return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
}
},
Bounce: {
easeOut: function(t,b,c,d){
if ((t/=d) < (1/2.75)) {
return c*(7.5625*t*t) + b;
} else if (t < (2/2.75)) {
return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
} else if (t < (2.5/2.75)) {
return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
} else {
return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
}
}
}
}
//容器对象,滑动对象,切换数量
var SlideTrans = function(container, slider, count, options) {
this._slider = $(slider);
this._container = $(container);//容器对象
this._timer = null;//定时器
this._count = Math.abs(count);//切换数量
this._target = 0;//目标值
this._t = this._b = this._c = 0;//tween参数
this.Index = 0;//当前索引
this.SetOptions(options);
this.Auto = !!this.options.Auto;
this.Duration = Math.abs(this.options.Duration);
this.Time = Math.abs(this.options.Time);
this.Pause = Math.abs(this.options.Pause);
this.Tween = this.options.Tween;
this.onStart = this.options.onStart;
this.onFinish = this.options.onFinish;
var bVertical = !!this.options.Vertical;
this._css = bVertical ? "top" : "left";//方向
//样式设置
var p = CurrentStyle(this._container).position;
p == "relative" || p == "absolute" || (this._container.style.position = "relative");
this._container.style.overflow = "hidden";
this._slider.style.position = "absolute";
this.Change = this.options.Change ? this.options.Change :
this._slider[bVertical ? "offsetHeight" : "offsetWidth"] / this._count;
};
SlideTrans.prototype = {
//设置默认属性
SetOptions: function(options) {
this.options = {//默认值
Vertical: true,//是否垂直方向(方向不能改)
Auto: true,//是否自动
Change: 0,//改变量
Duration: 50,//滑动持续时间
Time: 10,//滑动延时
Pause: 4000,//停顿时间(Auto为true时有效)
onStart: function(){},//开始转换时执行
onFinish: function(){},//完成转换时执行
Tween: Tween.Quart.easeOut//tween算子
};
Extend(this.options, options || {});
},
//开始切换
Run: function(index) {
//修正index
index == undefined && (index = this.Index);
index < 0 && (index = this._count - 1) || index >= this._count && (index = 0);
//设置参数
this._target = -Math.abs(this.Change) * (this.Index = index);
this._t = 0;
this._b = parseInt(CurrentStyle(this._slider)[this.options.Vertical ? "top" : "left"]);
this._c = this._target - this._b;
this.onStart();
this.Move();
},
//移动
Move: function() {
clearTimeout(this._timer);
//未到达目标继续移动否则进行下一次滑动
if (this._c && this._t < this.Duration) {
this.MoveTo(Math.round(this.Tween(this._t++, this._b, this._c, this.Duration)));
this._timer = setTimeout(Bind(this, this.Move), this.Time);
}else{
this.MoveTo(this._target);
this.Auto && (this._timer = setTimeout(Bind(this, this.Next), this.Pause));
}
},
//移动到
MoveTo: function(i) {
this._slider.style[this._css] = i + "px";
},
//下一个
Next: function() {
this.Run(++this.Index);
},
//上一个
Previous: function() {
this.Run(--this.Index);
},
//停止
Stop: function() {
clearTimeout(this._timer); this.MoveTo(this._target);
}
};
</SCRIPT>
<SCRIPT>
var forEach = function(array, callback, thisObject){
if(array.forEach){
array.forEach(callback, thisObject);
}else{
for (var i = 0, len = array.length; i < len; i++) { callback.call(thisObject, array[i], i, array); }
}
}
var st = new SlideTrans("idContainer2", "idSlider2", 6, { Vertical: false });
var nums = [];
//插入数字
for(var i = 0, n = st._count - 1; i <= n;){
(nums[i] = $("idNum").appendChild(document.createElement("li"))).innerHTML = ++i;
}
forEach(nums, function(o, i){
o.onmouseover = function(){ o.className = "on"; st.Auto = false; st.Run(i); }
o.onmouseout = function(){ o.className = ""; st.Auto = true; st.Run(); }
})
//设置按钮样式
st.onStart = function(){
forEach(nums, function(o, i){ o.className = st.Index == i ? "on" : ""; })
}
st.Run();
</SCRIPT>代码全部贴给大家了,可以正常运行,只是幻灯片优先级总是高于菜单的。所以菜单栏有些地方总是被幻灯片遮挡无法显示。求各位大虾帮忙解决呀,谢谢啦^_^
是不是有一个下拉菜单,然后鼠标移动到上面以后会出现一个下拉菜单,
有问题的地方应该是下拉菜单被你的幻灯片遮挡住了吧?貌似应该是层的优先级问题,你应该着手查看CSS样式吧,不应该找JS的问题。