JavaScript+div实现不间断向左滚动文字效果

本文介绍如何使用JavaScript创建一个连续向左滚动的文字效果,包括HTML、CSS和JavaScript的基本应用,适合前端开发者学习。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head>     <title>New Document </title>     <meta name="Generator" content="EditPlus">     <meta name="Author" content="">     <meta name="Keywords" content="">     <meta name="Description" content=""> </head> <body>     <html>     <head>         <meta http-equiv="Content-Type" content="text/html; charset=gb2312">         <title>连续向左滚动文字效果</title>         <style type="text/css"> <!-- body {font-size: 9pt;color: #000000;}{color: #0000FF;text-decoration: none;} a:hover {color: #FF0000;text-decoration: underline;} --> </style>     </head>     <body>         <div id="marquees">             赶紧干你的活去否则!嘿嘿,不给你发钱 赶紧干你的活去否则!嘿嘿,不给你发钱赶紧干你的活去否则!嘿嘿,不给你发钱         </div>         <div id="templayer" style="position: absolute; left: 0; top: 0; visibility: hidden">         </div>         <script language="JavaScript">                          marqueesWidth=500//控制滚动宽度                 with(marquees){                     style.height=0;                     style.width=marqueesWidth;                     style.overflowX="hidden";                     style.overflowY="visible";                     noWrap=true;                     onmouseover=new Function("stopscroll=true");                     onmouseout=new Function("stopscroll=false");                 }                     preLeft=0; currentLeft=0; stopscroll=false;                 function init(){                     templayer.innerHTML="";                     while(templayer.offsetWidth<marqueesWidth){                     templayer.innerHTML+=marquees.innerHTML;                 }                     marquees.innerHTML+=templayer.innerHTML;                     setInterval("scrollLeft()",20); //这里控制速度                 }init();                 function scrollLeft(){                 if(stopscroll==truereturn;                         preLeft=marquees.scrollLeft;                         marquees.scrollLeft+=1;                     if(preLeft==marquees.scrollLeft){                         marquees.scrollLeft=templayer.offsetWidth-marqueesWidth+1;                     }                 }         </script>     </body>     </html> </body> </html>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值