javascript scroll制作
<script><br />
var wrap=document.getElementById('wrap');<br />
var list1=document.getElementById('list1');<br />
var list2=document.getElementById('list2');<br />
var prev=document.getElementById('prev');<br />
var next=document.getElementById('next');<br />
//建立複製一份內容清單<br />
list2.innerHTML=list1.innerHTML;<br />
//向左循環滾動<br />
function scroll(){<br />
if(wrap.scrollLeft>=list2.offsetWidth){<br />
wrap.scrollLeft=0;<br />
}<br />
else{<br />
wrap.scrollLeft ;<br />
}<br />
}<br />
timer = setInterval(scroll,1);<br />
//滑鼠停留使用clearInterval()<br />
wrap.onmouseover=function(){<br />
clearInterval(timer);<br />
}<br />
wrap.onmouseout=function(){<br />
timer = setInterval(scroll,1);<br />
}<br />
//向左加速<br />
function scroll_l(){<br />
if(wrap.scrollLeft>=list2.offsetWidth){<br />
wrap.scrollLeft=0;<br />
}<br />
else{<br />
wrap.scrollLeft ;<br />
}<br />
}<br />
//向右滾動<br />
function scroll_r(){<br />
if(wrap.scrollLeft<=0){<br />
wrap.scrollLeft =list2.offsetWidth;<br />
}<br />
else{<br />
wrap.scrollLeft--;<br />
}<br />
} <br />
prev.onclick=function(){<br />
clearInterval(timer);<br />
change(0)<br />
}<br />
next.onclick=function(){<br />
clearInterval(timer);<br />
change(1)<br />
}<br />
function change(r){<br />
if(r==0){<br />
timer = setInterval(scroll_l,60);<br />
wrap.onmouseout = function(){<br />
timer = setInterval(scroll_l,60);<br />
}<br />
}<br />
if(r==1){<br />
timer = setInterval(scroll_r,60);<br />
wrap.onmouseout = function(){<br />
timer = setInterval(scroll_r,60);<br />
}<br />
} <br />
} <br />
</script>