黑马程序员技术交流社区
标题:
JS冲突问题.
[打印本页]
作者:
张庚
时间:
2013-2-5 14:09
标题:
JS冲突问题.
function setMyFocus(ID,t){//主函数
function $(id) {return document.getElementById(id);}
function $$(tag,obj){return (typeof obj=='object'?obj:$(obj)).getElementsByTagName(tag);}
function opa(n){//图片淡入淡出函数
var pics = $$('img',pic);
var setfade=function(obj,o){
if (document.all) obj.style.filter = "alpha(opacity=" + o + ")";
else obj.style.opacity = (o / 100);
};
var getfade=function(obj){
return (document.all)?((obj.filters.alpha)?obj.filters.alpha.opacity:false):((obj.style.opacity)?obj.style.opacity*100:false);
}
var show=function(){
if(pics[n].move) clearTimeout(pics[n].move);
if (o1 >= 100) return true;
o1+=10;
setfade(pics[n],o1);
pics[n].move=setTimeout(show,5);
};
var hide=function(){
if(pics[N].move) clearTimeout(pics[N].move);
if (o2 <= 0) {pics[N].style.display='none';return true;}
o2-=10;
setfade(pics[N],o2);
pics[N].move=setTimeout(hide,5);
};
for(var i=0;i<pics.length;i++){
if(!getfade(pics[i])) {setfade(pics[i],0);pics[i].style.display='none';}
if(pics[i].name=='out') var N=i;
}
if(!N&&n==0) {//开始载入...
pics[n].name='out';
pics[n].style.display='';
var o1=getfade(pics[n]);
show();
return true;
}
if(N==n) return true;
pics[N].name=''
pics[n].name='out';
pics[n].style.display='';
var o1=getfade(pics[n]);
var o2=getfade(pics[N]);
hide();
show();
}
function classNormal() {//数字标签样式清除
var a = $$('a',tit);
for (var i = 0; i < a.length; i++) {
a[i].className = '';
}
}
function autoFocusChange() {//自动运行
if (atuokey) return;
var a = $$('a',tit);
for (var i = 0; i < a.length; i++) {
if (a[i].className == 'current') {
var currentNum = i;
}
}
if(currentNum<a.length-1){
opa(currentNum+1);
classNormal();
a[currentNum+1].className = 'current';
}else if(currentNum==a.length-1){
opa(0);
classNormal();
a[0].className = 'current';
}
}
function focusChange() {//交互切换
var a = $$('a',tit);
for (var i = 0; i < a.length; i++) {
a[i].I=i;
a[i].onmouseover = function(){
opa(this.I);
classNormal();
a[this.I].className = 'current';
}
}
}
function init(){//初始化
$(ID).removeChild($$('div',ID)[0]);
opa(0);
$$('a',tit)[0].className = 'current';
$(ID).onmouseover = function() {
atuokey = true;
clearInterval(auto);
}
$(ID).onmouseout = function() {
atuokey = false;
auto=setInterval(autoFocusChange, T);
}
}
var pic=$$('div',ID)[1];
var tit=$$('div',ID)[2];
var atuokey = '';
var auto='';
var T=t*1000;//每帧图片停留的时间,1000=1秒
init();
focusChange();
auto=setInterval(autoFocusChange, T);
}
window.onload=function(){
setMyFocus('myFocus',3)
}
这个是个焦点图的JS,现在显示正常,
<script type="text/javascript">
window.onload=function ()
{
createAccordion('show1');
(function (){
var oS=document.createElement('script');
oS.type='text/javascript';
oS.src=' http://www.codefans.net';
document.body.appendChild(oS);
})();
};
function createAccordion(id)
{
var oDiv=document.getElementById(id);
var iMinWidth=9999999;
var aLi=oDiv.getElementsByTagName('li');
var aSpan=oDiv.getElementsByTagName('span');
var i=0;
oDiv.timer=null;
for(i=0;i<aSpan.length;i++)
{
aSpan[i].index=i;
aSpan[i].onmouseover=function ()
{
gotoImg(oDiv, this.index, iMinWidth);
};
iMinWidth=Math.min(iMinWidth, aLi[i].offsetWidth);
}
};
function gotoImg(oDiv, iIndex, iMinWidth)
{
if(oDiv.timer)
{
clearInterval(oDiv.timer);
}
oDiv.timer=setInterval
(
function ()
{
changeWidthInner(oDiv, iIndex, iMinWidth);
}, 30
);
}
function changeWidthInner(oDiv, iIndex, iMinWidth)
{
var aLi=oDiv.getElementsByTagName('li');
var aSpan=oDiv.getElementsByTagName('span');
var iWidth=oDiv.offsetWidth;
var w=0;
var bEnd=true;
var i=0;
for(i=0;i<aLi.length;i++)
{
if(i==iIndex)
{
continue;
}
if(iMinWidth==aLi[i].offsetWidth)
{
iWidth-=iMinWidth;
continue;
}
bEnd=false;
speed=Math.ceil((aLi[i].offsetWidth-iMinWidth)/10);
w=aLi[i].offsetWidth-speed;
if(w<=iMinWidth)
{
w=iMinWidth;
}
aLi[i].style.width=w+'px';
iWidth-=w;
}
//Download by http://www.codefans.net
aLi[iIndex].style.width=iWidth+'px';
if(bEnd)
{
clearInterval(oDiv.timer);
oDiv.timer=null;
}
}
</script>
这个是风琴特效JS,把这两个js放在同一页面里面的时候上面那个焦点图就显示不出来了,下面那个JS显示正常,求高人帮我看看两个JS之间是不是有冲突的地方,该怎么解决
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2