SoFunction
Updated on 2025-04-10

Use marquee and div+js to achieve the end-to-end loop scrolling effect, with only 3 lines of code


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">
<HTML xmlns="http:///1999/xhtml">
<HEAD>
<TITLE>Use marquee and div+js respectively to achieve the end-to-end loop scrolling effect</TITLE>
</HEAD>
<BODY>
Use marquee to achieve the end-to-end cyclic scrolling effect (IE only):<br /><br />
<MARQUEE behavior="scroll" contenteditable="true" onstart="+=;" scrollamount="3" width="100"><SPAN unselectable="on">This is the content to scroll</SPAN></MARQUEE>
<br /><br />Use DIV+javascript to achieve the end-to-end loop scrolling effect (compatible with firefox):<br /><br />
<DIV style="white-space:nowrap;overflow:hidden;width:500px;"><span>This is what to scroll</span></DIV>
<script language="javascript" type="text/javascript">
<!--
function scroll(obj) {
var tmp = ()++;
//When the scroll bar reaches the top on the right
if (==tmp) += ;
// When the scrollbar scrolls the width of the initial content, the scrollbar returns to the leftmost end
if (>=) =0;
}
setInterval("scroll(('scrollobj'))",20);
//-->
</script>
</BODY>
</HTML>