Apt articles on health, wealth, happiness

Free double scrolling and pausing script

Link to this article!



If you know what you want, then on this page you will find a script you can use now, right now. So, what do you need? This script can do wonders for your web site. Look no further, if you want a free JavaScript that works on two sets of text, makes them scroll vertically, pauses after each paragraph, and pauses on mouse over.

Author: AptArticle.com

Description: It is Java Script that works on two blocks of text, scrolls them vertically, and pauses after each paragraph.

Demo: The following example shows what this script can do for you. Notice that:
  • There is an initial delay of a few seconds.
  • By editing, you can modify the duration of this delay.
  • Scrolling pauses after each message.
  • By editing, you can modify the duration of this pause.
  • Scrolling pauses on mouse over.
  • By editing, you can eliminate this pause.
  • By editing, you can speed up and slow down the scrolling.


Directions:

Step 1: Copy the following code, and add it to the 'body' section of your web page.

<script>
new scroller(mycontent, "scroller1", "classA", 5000)    /* may edit this 5000 */
document.write("<br>")
new scroller(mycontent2, "scroller2", "classA", 5000)   /* may edit this 5000 */
</script>
 


Step 2: Copy the following code, and add it to the 'CSS' file of your web site.

#scroller1 {
width: 600px;         /* may edit */
height: 70px;           /* may edit */
border: 1px solid #0000A0; /* may edit */
padding-bottom: 20px;        /* may edit */
background-color: #F1F1F1;     /* may edit */
}

#scroller2 {
width: 600px;        /* may edit */
height: 70px;           /* may edit */
border: 1px solid #0000A0; /* may edit */
padding-bottom: 20px;         /* may edit */
background-color: #F1F1F1;       /* may edit */
}

.classA {
font-family: Arial; /* may edit */
}
 


Step 3: Copy the following code, and add it to the 'head' section of your web page.

<script>
var mycontent=new Array()
mycontent[0]='Your paragraph 1'   /* may edit */
mycontent[1]='Your paragraph 2'   /* may edit */
mycontent[2]='Your paragraph 3'   /* may edit */

var mycontent2=new Array()
mycontent2[0]='Your paragraph 4'  /* may edit */
mycontent2[1]='Your paragraph 5'  /* may edit */
mycontent2[2]='Your paragraph 6'  /* may edit */
</script>

<script>
function scroller(content, divId, divClass, delay){
this.content=content
this.tickerid=divId
this.delay=delay
this.mouseoverBol=0  /* 0 or 1, may edit */
this.hiddendivpointer=1
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>') /* all of this should be ONE long line of code */

var scrollerinstance=this
if (window.addEventListener)
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent)
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById)
setTimeout(function(){scrollerinstance.initialize()}, 500) /* may edit this 500 */
}

/******* DO NOT EDIT BELOW THIS LINE ************/

/*********************************************************
* Copyright © AptArticle.com (http://aptarticle.com)
* This notice MUST stay intact for legal use.
* Visit http://aptarticle.com/ for this script and hundreds more.
*********************************************************************/

scroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(scroller.getCSSpadding(this.tickerdiv))
this.visiblediv.style.width=this.hiddendiv.style.width= this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px" /* all of this should be ONE long line of code */

this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=
function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=
function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent)
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover= scrollerinstance.tickerdiv.onmouseout=null}) /* all of this should be ONE long line of code */

setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}

scroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

scroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

scroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

scroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

scroller.getCSSpadding=function(tickerobj){
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle)
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}
</script>
 


Step 4: You may edit the code you've copied in steps 1 through 3.
However, in your own interest, do limit your editing to lines we marked /* may edit */.


Step 5: Enjoy it! Have fun using it!


Tell a friend!