熱點新聞滾動特效的js代碼
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>熱點新聞滾動</title>
<style type="text/css">
<!--
body {
margin: 0px;
font-size: 12px;
color: #938C43;
line-height: 150%;
text-align:center;
}
a:link{color: #9D943A;font-size:12px;}
a:hover{color: #FF3300;font-size:12px;}
a:visited{color: #9D943A;font-size:12px;}
a.red:link{color: #ff0000;font-size:12px;}
a.red:hover{color: #ff0000;font-size:12px;}
a.red:visited{color: #ff0000;font-size:12px;}
#marqueeBox{background:#f7f7f7;border:1px solid silver;padding:1px;text-align:center;margin:0 auto;}
-->
</style>
</head>
<body>
<h4>滾動新聞</h4>
<script language="JavaScript" type="text/javascript">
var marqueeContent=new Array();
marqueeContent[0]="<a href='http://www.dbjr.com.cn' target='_blank'>腳本之家</a>";
marqueeContent[1]="<a target='_blank'>播放器之家</a>";
marqueeContent[2]="<a target='_blank'>素材之家</a>";
marqueeContent[3]="<a target='_blank'>個性名字網(wǎng)</a>";
var marqueeInterval=new Array();
var marqueeId=0;
var marqueeDelay=2000;
var marqueeHeight=20;
function initMarquee() {
var str=marqueeContent[0];
document.write('<div id="marqueeBox" style="overflow:hidden;width:250px;height:'+marqueeHeight+'px" onmouseover="clearInterval(marqueeInterval[0])" onmouseout="marqueeInterval[0]=setInterval('startMarquee()',marqueeDelay)"><div>'+str+'</div></div>');
marqueeId++;
marqueeInterval[0]=setInterval("startMarquee()",marqueeDelay);
}
function startMarquee() {
var str=marqueeContent[marqueeId];
marqueeId++;
if(marqueeId>=marqueeContent.length) marqueeId=0;
if(document.getElementById("marqueeBox").childNodes.length==1) {
var nextLine=document.createElement('DIV');
nextLine.innerHTML=str;
document.getElementById("marqueeBox").appendChild(nextLine);
}
else {
document.getElementById("marqueeBox").childNodes[0].innerHTML=str;
document.getElementById("marqueeBox").appendChild(document.getElementById("marqueeBox").childNodes[0]);
document.getElementById("marqueeBox").scrollTop=0;
}
clearInterval(marqueeInterval[1]);
marqueeInterval[1]=setInterval("scrollMarquee()",20);
}
function scrollMarquee() {
document.getElementById("marqueeBox").scrollTop++;
if(document.getElementById("marqueeBox").scrollTop%marqueeHeight==(marqueeHeight-1)){
clearInterval(marqueeInterval[1]);
}
}
initMarquee();
</script>
</body>
</html></td>
</tr>
</table>
相關(guān)文章
ES6中的class是如何實現(xiàn)的(附Babel編譯的ES5代碼詳解)
這篇文章主要介紹了ES6中的class是如何實現(xiàn)的?(附Babel編譯的ES5代碼詳解),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-05-05JS獲取中文拼音首字母并通過拼音首字母快速查找頁面內(nèi)對應(yīng)中文內(nèi)容的方法【附demo源碼】
這篇文章主要介紹了JS獲取中文拼音首字母并通過拼音首字母快速查找頁面內(nèi)對應(yīng)中文內(nèi)容的方法,涉及javascript針對字符串的遍歷、查找、正則匹配及轉(zhuǎn)換等操作技巧,并附帶完整demo源碼供讀者下載參考,需要的朋友可以參考下2016-08-08Js動態(tài)設(shè)置rem來實現(xiàn)移動端字體的自適應(yīng)代碼
這篇文章主要介紹了Js動態(tài)設(shè)置rem來實現(xiàn)移動端字體的自適應(yīng)代碼,代碼簡單易懂非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-10-10