我無(wú)限滾動(dòng)了一輪后會(huì)出現(xiàn)圖片位置不一樣,比如原來(lái)的index=1的圖片變到了index=3的位置
我無(wú)限滾動(dòng)了一輪后會(huì)出現(xiàn)圖片位置不一樣,第一輪的情況正常,但是到了第二輪的時(shí)候,比如按下向右箭頭原來(lái)的index=1的圖片變到了index=3的位置或者其他位置,按下左箭頭也會(huì)出現(xiàn)這樣的情況.
window.onload=function(){
??????????? var container=document.getElementById('container');
??????????? var list=document.getElementById('list');
??????????? var buttons=document.getElementById('buttons').getElementsByTagName('span');
??????????? var next=document.getElementById('next');
??????????? var prev=document.getElementById('prev');
??????????? var index=1;
??????????? function animate(offset){
??????????????? var newLeft=parseInt(list.style.left)+offset;
??????????????? list.style.left=newLeft+'px';
??????????????? if(newLeft<-6000){
??????????????????? list.style.left=-1000+'px';
??????????????? }
??????????????? if(newLeft>-1000){
??????????????????? list.style.left=-6000+'px';
??????????????? }
??????????? }
??????????? function showButton(){
??????????????? for(var i=0;i<buttons.length;i++){
??????????????????? if(buttons[i].className=='on'){
??????????????????????? buttons[i].className='';
??????????????????????? break;
??????????????????? }
??????????????? }
??????????????? buttons[index-1].className='on';
??????????? }
??????????? next.onclick=function(){
???????????????
??????????????? if(index==5){
??????????????????? index=1;
??????????????? }
??????????????? else{
??????????????????? index+=1;
??????????????? }
??????????????? animate(-1000);
??????????????? showButton();
??????????? }
??????????? prev.onclick=function(){
???????????????
??????????????? if(index==1){
??????????????????? index=5;
??????????????? }
??????????????? else{
??????????????????? index-=1;
??????????????? }
??????????????? animate(1000);
??????????????? showButton();
??????????? }
??????????? for(var i=0;i<buttons.length;i++){
??????????????? buttons[i].onclick=function(){
??????????????????? if(this.className=='on'){
??????????????????????? return;
??????????????????? }
??????????????????? var myIndex=parseInt(this.getAttribute('index'));
??????????????????? var offset=-1000*(myIndex-index);
??????????????????? animate(offset);
??????????????????? index=myIndex;
??????????????????? showButton();
??????????????? }
??????????? }
??????? }
2019-05-16
我也有出現(xiàn)這個(gè)問(wèn)題。
2019-03-16
把-6000換成-5000試試