1:javascript:javascript
function showAnimateLine() { var speed=6; function Marquee(){ if(document.getElementById("line1").offsetWidth-document.getElementById("line").scrollLeft<=0){ document.getElementById("line").scrollLeft-=document.getElementById("line1").offsetWidth; } else{ document.getElementById("line").scrollLeft++; } } setInterval(Marquee,speed); }
2:jquery:java
function showAnimateLine() { var speed=6; var scrollLeft=0; function Marquee(){ if($("#line1").width()-$("#line").scrollLeft()<=0){ scrollLeft -=$("#line1").width(); $("#line").scrollLeft(scrollLeft); }else{ scrollLeft++; $("#line").scrollLeft(scrollLeft); } } setInterval(Marquee,speed); }
將這兩個實現方法寫在一塊兒的用意是 加深理解 offsetWidth scrollLeft width() innerwidth() outerWidth() scrollLeft() 之間的區別。jquery