日期:2014-05-16 浏览次数:20412 次
<html> <head> <title>无缝垂直图片滚动</title> </head> <body> <div id=demo style=overflow:hidden;height:100;width:180;> <div id=demo1> <img src="http://codefans.net/images/logo.gif" onclick="javascript:window.open(this.src);"> <img src="http://codefans.net/images/logo.gif" onclick="javascript:window.open(this.src);"> <img src="http://codefans.net/images/logo.gif" onclick="javascript:window.open(this.src);"> <img src="http://codefans.net/images/logo.gif" onclick="javascript:window.open(this.src);"> <img src="http://codefans.net/images/logo.gif" onclick="javascript:window.open(this.src);"> <img src="http://codefans.net/images/logo.gif" onclick="javascript:window.open(this.src);"> <img src="http://codefans.net/images/logo.gif" onclick="javascript:window.open(this.src);"> <img src="http://codefans.net/images/logo.gif" onclick="javascript:window.open(this.src);"> </div> <div id=demo2></div> </div> <script> var speed=30 demo2.innerHTML=demo1.innerHTML function Marquee(){ if(demo2.offsetTop-demo.scrollTop<=0) demo.scrollTop-=demo1.offsetHeight else{ demo.scrollTop++ } } var MyMar=setInterval(Marquee,speed) demo.onmouseover=function() {clearInterval(MyMar)} demo.onmouseout=function(){MyMar=setInterval(Marquee,speed)} </script> </body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>javascript无缝滚动</title> <meta charset="gb2312"/> <style type="text/css"> #marquee ,#marquee li { padding:0px; margin:0px;} #marquee { position:relative; list-style:none; height:150px; width:210px; padding-left:5px; overflow:hidden; border:10px solid #eee; } #marquee li { position:absolute; font-size:12px;} #marquee a { display:block; color:#999999; text-decoration:none;} </style> <script type="text/javascript"> var Marquee = function(id){ try{document.execCommand("BackgroundImageCache", false, true);}catch(e){}; var container = document.getElementById(id), slide = container.getElementsByTagName("li")[0], speed = arguments[1] || 80, //速度 delta = 0,//当前滚动的位置 critical = slide.offsetHeight;//临界点 slide.innerHTML += slide.innerHTML; var rolling = function(){ delta == -critical ? delta = 0 : delta--; slide.style.top = delta + "px"; } var timer = setInterval(rolling,speed)//设置定时器 container.onmouseover=function() {clearInterval(timer)}//鼠标移到marquee上时,清除定时器,停止滚动 container.onmouseout=function() {timer=setInterval(rolling,speed)}//鼠标移开时重设定时器 } window.onload = function(){ Marquee("marquee"); } </script> </head> <body> <ul id="marquee"> <li> <a href="#">纤云弄巧,飞星传恨,银汉迢迢暗度。</a><br /> <a href="#">金风玉露一相逢,便胜却、人间无数。</a><br /> <a href="#">柔情似水,佳期如梦。忍顾鹊桥归路!</a><br /> <a href="#">两情若是久长时,又岂在、朝朝暮暮。</a><br /> <a href="#">千重劫,百世难,亘古匆匆,弹指间!</a><br /> <a href="#">不死躯,不灭魂,震古烁今,无人敌!</a><br /> <a href="#">待到阴阳逆乱时,以我魔血染青天!</a><br /> </li> </ul> </body> </html>