猿问

请问这个函数的弊端在哪里 问题在哪里有人帮忙分析一下吗

function companyMove(){
    var bigBox=document.getElementById('company_box');
    var companyContent=getByClass(bigBox,'company_content');
    var oListsWidth=parseInt(getStyle(companyContent[0],'width'));
    var oListsHeight=getStyle(companyContent[0],'height');
    var companyBox=getByClass(bigBox,'company_content_box')[0];
    var oBtn=document.getElementById('company_btn');
    var aBtnLists=oBtn.getElementsByTagName('a');
    var onNow=0;
    
    companyContent.timer1=null;
    companyContent.timer2=null;
    companyBox.style.width=parseInt(oListsWidth)*companyContent.length+'px';
    //alert(companyBox.style.width);
    
    //aBtnLists[1].className='company_btn_checked';
    function a(){
        clearInterval(companyContent.timer2);//清楚第二个定时器
        companyContent.timer1=setInterval(function(){//开启第一个定时器
            onNow+=-oListsWidth;
            startMove(companyBox,{left:onNow},15);            
            if(onNow<=-oListsWidth*(companyContent.length-1))
            {
                b();
            }
            for(var i=0 ; i<aBtnLists.length ; i++)
            {
                aBtnLists[i].className='';
            }

            aBtnLists[Math.abs(onNow/oListsWidth)].className='company_btn_checked';

        },5000);    

    }
    function b(){
        clearInterval(companyContent.timer1);
        companyContent.timer2=setInterval(function(){
            onNow+=oListsWidth;
            startMove(companyBox,{left:onNow},15);        
             if(onNow>=0)
            {        
                a();
            }        
            for(var i=0 ; i<aBtnLists.length ; i++)
            {
                aBtnLists[i].className='';    
            }

            aBtnLists[Math.abs(onNow/oListsWidth)].className='company_btn_checked';
            
            
        },5000);

    }
    
    a();
    
    companyBox.onmouseover=function(){
        clearInterval(companyContent.timer1);
        clearInterval(companyContent.timer2);
    }
    companyBox.onmouseout=function(){
        a();
    }



}


qq_小狼丶_03974697
浏览 1290回答 1
1回答

我是大牛你信么

不是挺好的么
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答