I used to write a jquery scroll between left and right. Now I want to achieve seamless scrolling of JavaScript.
In an example on the Internet, I feel that the rolling process is unstable and the process is getting faster. Below is the code I modified:
Js:
<Script>
Var speed = 20 // The greater the speed, the slower the speed.
Var www_qpsh_com2 = null;
Var www_qpsh_com1 = null;
Var www_qpsh_com = null;
Var MyMar = null;
Function load (){
Www_qpsh_com2 = document. getElementById ("www_qpsh_com2 ");
Www_qpsh_com1 = document. getElementById ("www_qpsh_com1 ");
Www_qpsh_com = document. getElementById ("www_qpsh_com ");
Var len = document. getElementById ("table"). getElementsByTagName ("td"). length;
If (len> 4) {// when there are fewer than four images in the image, the image does not scroll because the total width of the image is smaller than the width of the display box.
Www_qpsh_com2.innerHTML = www_qpsh_com1.innerHTML; // copy the content in 1 to this id for seamless operation.
Marquee ();
}
}
Function over (){
ClearTimeout (MyMar );
}
Function out (){
MyMar = setTimeout ("Marquee ()", speed );
}
Function Marquee (){
If (www_qpsh_com2.offsetWidth-www_qpsh_com.scrollLeft <= 0)
Www_qpsh_com.scrollLeft-= www_qpsh_com1.offsetWidth
Else {
Www_qpsh_com.scrollLeft ++;
}
MyMar = setTimeout ("Marquee ()", speed );
}
</Script>
Jsp page:
<Div id = www_qpsh_com onmouseout = "out ()">
<Table align = left cellpadding = 0 cellspace = 0 border = 0>
<Tr>
<Td id = www_qpsh_com1 valign = top>
<Table border = 0 cellpadding = 0 cellspacing = 0 id = "table">
<Tr>
<Td>
</Td>
<Td>
</Td>
<Td>
</Td>
<Td>
</Td>
<Td>
</Td>
</Tr>
</Table>
</Td>
<Td id = www_qpsh_com2 valign = top> </td>
</Tr> </table>
</Div>
This article is from the "IT" blog, please be sure to keep this source http://3795780.blog.51cto.com/3785780/1303320