本文為大家分享了js文字橫向滾動特效代碼,具體實現內容如下:
頁面布局
<div id="scroll_div" class="fl"> <div id="scroll_begin"> 恭喜793765***獲得 <span class="pad_right">50元巨人點卡獎勵</span> 恭喜793765***獲得 <span class="pad_right">50元巨人點卡獎勵</span> 恭喜793765***獲得 <span class="pad_right">50元巨人點卡獎勵</span> 恭喜793765***獲得 <span class="pad_right">50元巨人點卡獎勵</span> 恭喜793765***獲得 <span class="pad_right">50元巨人點卡獎勵</span> 恭喜793765***獲得 <span class="pad_right">50元巨人點卡獎勵</span> 恭喜793765***獲得 <span class="pad_right">50元巨人點卡獎勵</span> </div> <div id="scroll_end"></div> </div>
樣式:
.pad_right{ padding-right:2em;} #scroll_div {height:26px;overflow: hidden;white-space: nowrap;width:535px;margin-left:10px;} #scroll_begin,#scroll_end {display: inline;}
js代碼:
//文字橫向滾動 function ScrollImgLeft(){ var speed=50; var MyMar = null; 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++; } MyMar=setInterval(Marquee,speed); scroll_div.onmouseover = function(){ clearInterval(MyMar); } scroll_div.onmouseout = function(){ MyMar = setInterval(Marquee,speed); } } ScrollImgLeft();
以上就是輕松實現js文字橫向滾動特效,大家可以在自己的網頁中添加js文字橫向滾動特效。