javascript - JS Animation really buggy -
i'm trying build image slider automatically takes div ids , animates them. far works buggy. animation lagging lot , when minimized tab, slides animated @ same time.
i made jsfiddle issue: https://jsfiddle.net/2cdwgvm7/
js:
function slider() { var counter = 0; var sliderebene = document.getelementbyid(imageids[counter]); sliderebene.style.left = '0px'; var counter = 1; var flag = true; var functionisrunning = true; function clickslider() { forward.addeventlistener('click', function () { functionisrunning = true; if (counter >= imageids.length) { counter = 0; } else { var sliderebene = document.getelementbyid(imageids[counter]); var pos = browserwidth; var id = setinterval(frame, 0.6); function frame() { if (pos == 0) { sliderebene.style.zindex = '0'; clearinterval(id); functionisrunning = false; } else { pos--; sliderebene.style.left = pos + 'px'; sliderebene.style.zindex = '1'; } } counter++; } }); } function autoslider() { if (counter >= imageids.length) { counter = 0; flag = false; } else { flag = true; var sliderebene = document.getelementbyid(imageids[counter]); var pos = browserwidth; var id = setinterval(frame, 0.6); function frame() { if (pos == 0) { sliderebene.style.zindex = '0'; clearinterval(id); } else { pos--; sliderebene.style.left = pos + 'px'; sliderebene.style.zindex = '1'; } } counter++; flag = false; } } function autoslidertimer() { if (flag) { autoslider(); } flag = !flag; console.log(flag); } function slidertimer() { if (!functionisrunning) { clickslider(); console.log('clickslider();'); }else if(flag){ setinterval(autoslidertimer, 10000); console.log('setinterval(autoslidertimer, 10000);'); } } slidertimer(); } slider();
Comments
Post a Comment