Paul McFedries' Web Home


Bouncing Status Bar Message

In this variation, the status bar message enters from the right, scrolls left until it hits the left edge of the status bar, and then scrolls right. It then lathers, rinses, and repeats. Once again, here are the instructions:

  • Copy everything between the <SCRIPT> and </SCRIPT> tags and insert it somewhere inside your Web page.
  • To specify the scrolling message, edit the following line in the script:
       var msg = "Enter your status bar message here"
    
  • To adjust the speed of the message, edit the following line (a smaller value gives you a faster scroll):
       var delay = 50
    
  • To adjust the starting position of the message, edit the following line (a smaller value starts the message closer to the left side of the window):
       var startPos = 100
    
Here's the full script:
<SCRIPT LANGUAGE="JavaScript">
<!--
// Use the following three variables to set up the message:
var msg = "Enter your status bar message here"
var delay = 50
var startPos = 100

// Don't touch these variables:
var timerID = null
var timerRunning = false
var pos = 0
var dir = 1
var msgLength = msg.length

// Crank it up!
StartScrolling()

function StartScrolling(){
    // Make sure the clock is stopped
    StopTheClock()

    // Pad the message with spaces to get the "start" position
    for (var i = 0; i < startPos; i++) msg = " " + msg

    // Off we go...
    DoTheScroll()
}

function StopTheClock(){
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function DoTheScroll(){
    if (dir == 1){
        if (pos <= startPos)
            self.status = msg.substring(pos, msg.length);
        else
            dir = -1;
    }
    else{
        if (pos >= msgLength)
            self.status = msg.substring(pos, msg.length);
        else
            dir = 1;
    }
    pos = pos + dir
    timerRunning = true
    timerID = self.setTimeout("DoTheScroll()", delay)
}
//-->
</SCRIPT>


Copyright © 1995-2008 Paul McFedries and Logophilia Limited