【JS】滚动字幕

描述

这里有2种滚幕效果,都是横向。

<!--滚动字幕(结尾不接开始) S-->
<div style="color:red;margin-top:10px;margin-bottom:-5px;">
<b>
<marquee>
通知:清明三天军都专家不放假,就诊高峰请提前预约专家号,每天仅限15名。(时间:4月2日-4日)
</marquee>
</b>
</div>
<!--滚动字幕(结尾不接开始) E-->


<!--滚动字幕(结尾接开始) S-->
<style type="text/css"> 
#gongao{margin-top:10px;margin-bottom:-5px;width:100%;height:30px;overflow:hidden;line-height:30px;font-size:13px;font-family:'宋体';color:red;font-weight:bold;} 
#gongao #scroll_begin, #gongao #scroll_end{display:inline;margin-left:50px;} 
</style> 

<script type="text/javascript"> 
function ScrollImgLeft(){ 
var speed=70; 
var scroll_begin = document.getElementById("scroll_begin"); 
var scroll_end = document.getElementById("scroll_end"); 
var scroll_div = document.getElementById("scroll_div"); 
scroll_end.innerHTML=scroll_begin.innerHTML; 
function Marquee(){ 
if(scroll_end.offsetWidth-scroll_div.scrollLeft<=0) 
scroll_div.scrollLeft-=scroll_begin.offsetWidth; 
else 
scroll_div.scrollLeft++; 
} 
var MyMar=setInterval(Marquee,speed); 
scroll_div.onmouseover=function() {clearInterval(MyMar);} 
scroll_div.onmouseout=function() {MyMar=setInterval(Marquee,speed);} 
} 
</script> 
<div id="gongao"> 
<div style="width:100%;height:30px;margin:0 auto;white-space: nowrap;overflow:hidden;" id="scroll_div" class="scroll_div"> 
<div id="scroll_begin"> 
通知:清明三天军都专家不放假,就诊高峰请提前预约专家号,每天仅限15名。(时间:4月2日-4日)
</div> 
<div id="scroll_end"></div> 
</div> 
<script type="text/javascript">ScrollImgLeft();</script> 
</div> 
<!--滚动字幕(结尾接开始) E-->

 

posted on 2016-08-09 09:57  一个小目标一次坑记录  阅读(366)  评论(0)    收藏  举报