Skip to content

Instantly share code, notes, and snippets.

@luobotang
Created June 9, 2014 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luobotang/f12b879a223f37cdc127 to your computer and use it in GitHub Desktop.
Save luobotang/f12b879a223f37cdc127 to your computer and use it in GitHub Desktop.
AutoScroll
// 自动滚动
// div#demo style:overflow:hidden
// div#demo1
// div#demo2
var SPEED = 60,
demo2 = document.getElementById("demo2"),
demo1 = document.getElementById("demo1"),
demo = document.getElementById("demo");
function Marquee() {
// demo1 显示完毕之后重新切换显示 demo1
if (demo.scrollTop >= demo2.offsetTop) {
demo.scrollTop -= demo1.offsetHeight;
} else {
demo.scrollTop++;
}
}
demo2.innerHTML = demo1.innerHTML;
var MyMar = setInterval(Marquee, SPEED);
demo.onmouseover=function() { clearInterval(MyMar); }
demo.onmouseout=function() {MyMar = setInterval(Marquee, SPEED); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment