问答详情
源自:4-1 无限滚动

总是报错,小黄点不能点~球解决~~~

window.onload=function(){
   var con=document.getElementById('con');
   var list=document.getElementById('list');
   var button=document.getElementById('button').getElementsByClassName('span');
   var prev=document.getElementById('prev');
   var next=document.getElementById('next');
   var index=1;

   function showButton(){
       button[index-1].className='on';

   }
   function animate(offset){
       var newleft=parseInt(list.style.left) +offset;
       list.style.left = newleft+ 'px';

       if(newleft>-730){
           list.style.left=-3650+'px';
       }
       if(newleft<-3650){
           list.style.left=-730+'px';
       }
   }
   next.onclick=function() {
       index += 1;
       showButton();
       animate(-730);
   }
   prev.onclick=function() {
       index -= 1;
       showButton();
       animate(730);
   }


}

提问者:qq_郑岚_0 2015-02-15 15:00

个回答

  • VincentLi
    2016-01-03 11:55:17

    for (var i = 0; i < buttons.length; i++) {

                    buttons[i].onclick = function(){

                        if (this.className == 'on') {

                            return;

                        }

                        var myIndex = this.getAttribute('index');

                        offset = -600 *(myIndex - index);

                        animate(offset);

                        index = myIndex;

                        showbutton();

                    }

                }

    加上这些