js text horizontal scroll effect

  • 2020-10-31 21:37:05
  • OfStack

This paper shares the js text horizontal scrolling effect code, the specific implementation is as follows:

The page layout


<div id="scroll_div" class="fl"> 
  <div id="scroll_begin">
    congratulations 793765*** To obtain  <span class="pad_right">50 Yuan Giant point card reward </span>
    congratulations 793765*** To obtain  <span class="pad_right">50 Yuan Giant point card reward </span>
    congratulations 793765*** To obtain  <span class="pad_right">50 Yuan Giant point card reward </span>
    congratulations 793765*** To obtain  <span class="pad_right">50 Yuan Giant point card reward </span>
    congratulations 793765*** To obtain  <span class="pad_right">50 Yuan Giant point card reward </span>
    congratulations 793765*** To obtain  <span class="pad_right">50 Yuan Giant point card reward </span>
    congratulations 793765*** To obtain  <span class="pad_right">50 Yuan Giant point card reward </span>
  </div> 
  <div id="scroll_end"></div>
 </div> 

Style:


.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 code:


// Horizontal scrolling 
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();

Above is the easy implementation of js text horizontal scrolling effects, you can add js text horizontal scrolling effects in your web pages.


Related articles: