View Full Version : Highlight Scroller won't center

01-04-2010, 11:34 PM
I think I'm missing something somewhere, but when I use the codes on a blank htm page, I just can't seem to get the script centered right.
(yes, the htm file has DOCTYPE at the top and all the necessary stuff)
The problem in centering it comes in when the length of the lines are different. If one line says:
New Specials Available Click Here To See them
and the second is:
Check out our sister site

Then the scroller isn't centered

One way I could get it centered but it turned out so that the beginning of the scroller was centered, not the entire line.
Another was I could center the first line, but then the 2nd wasn't centered because it was shorter.

What am I missing?

01-05-2010, 05:35 AM
Hello Tracy_Lit5,
To center an element, you need three things:

a DocType
an element with a width
that elements left/right margins set to auto

It sounds like your scroller does not have a width?
Can you show us some code or a link to the test site?

01-05-2010, 12:36 PM
Here's a link to where I got the script.
I'm trying to center the script so that each line that appears will be centered inside an element, table or web page.

01-05-2010, 05:21 PM
Goodmorning Tracy_LIt5,
That can be centered by removing the absolute positioning. The text-align:center; on #container in this example cascades down then.
Of course, it wrecks the whole scrolling affect.
Need someone better with js to edit the script itself to make it work right.

Try this for now -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
html, body {
font: 100% "Comic Sans MS";
background: #FC6;
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
#container {
width: 800px;
margin: 30px auto;
background: #999;
overflow: auto;
font-size: 0.8em;
text-align: center;
<div id="container">
<div style="position:relative;left:0px;top:0px">
<span id="highlighter" style="font-size:18px;font-family:Verdana;background-color:yellow;clip:rect(0px 0px auto 0px)"></span>

<script type="text/javascript">

Highligher Scroller script- By JavaScript Kit
For this and over 400+ free scripts, visit http://www.javascriptkit.com/
This notice must stay intact

var tickercontents=new Array()
tickercontents[0]='Looking for free Java applets and resources? Visit <a href="http://freewarejava.com">Freewarejava.com</a>!'
tickercontents[1]='Hop on over to <a href="http://www.codingforums.com">Coding Forums</a> to get help on web coding!'
tickercontents[2]='This scroller\'s brought to you by <a href="http://www.javascriptkit.com">JavaScript Kit</a>'

var tickdelay=3000 //delay btw messages
var highlightspeed=10 //10 pixels at a time.

////Do not edit pass this line////////////////

var currentmessage=0
var clipwidth=0

function changetickercontent(){
crosstick.style.clip="rect(0px 0px auto 0px)"

function highlightmsg(){
var msgwidth=crosstick.offsetWidth
if (clipwidth<msgwidth){
crosstick.style.clip="rect(0px "+clipwidth+"px auto 0px)"
if (currentmessage==tickercontents.length-1) currentmessage=0
else currentmessage++

function start_ticking(){
crosstick=document.getElementById? document.getElementById("highlighter") : document.all.highlighter
crosstickParent=crosstick.parentNode? crosstick.parentNode : crosstick.parentElement
if (parseInt(crosstick.offsetHeight)>0)
setTimeout("crosstickParent.style.height=crosstick.offsetHeight+'px'",100) //delay for Mozilla's sake

if (document.all || document.getElementById)


<p>This free script provided by<br />
<a href="http://javascriptkit.com">JavaScript Kit</a></p>
<!--end container--></div>