1. 程式人生 > >js實現水平滑動和垂直滑動

js實現水平滑動和垂直滑動

//要想滑動不停 scroll_begin的內容寬度必須大於scroll_div的寬度 function ScrollImgLeft(){ var speed=50; var scroll_begin = document.getElementById("scroll_begin"); var scroll_end = document.getElementById("scroll_end"); var scroll_div = document.getElementById("scroll_div"
); scroll_end.innerHTML=scroll_begin.innerHTML; function Marquee(){ //offsetWidth width + border + padding //scrollleft 滑動條起點向右滑動的距離 當一個div顯示完後 迅速重置滑動條的起點為最左端 重新顯示div內容 if(scroll_end.offsetWidth-scroll_div.scrollLeft<=0
) scroll_div.scrollLeft-=scroll_begin.offsetWidth; else scroll_div.scrollLeft++; } var MyMar=setInterval(Marquee,speed); scroll_div.onmouseover=function() {clearInterval(MyMar);} scroll_div.onmouseout=function
() {
MyMar=setInterval(Marquee,speed);} }