Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Highlight Scroller won't center

    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?

  • #2
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,747
    Thanks
    22
    Thanked 1,838 Times in 1,822 Posts
    Hello Tracy_Lit5,
    To center an element, you need three things:
    1. a DocType
    2. an element with a width
    3. 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?
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #3
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool

    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.
    http://www.javascriptkit.com/script/cut57.shtml

  • #4
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,747
    Thanks
    22
    Thanked 1,838 Times in 1,822 Posts
    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 -
    Code:
    <!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">
    <head>
    <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;
    }
    </style>
    </head>
    <body>
        <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>
    </div>
    
    <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)"
    crosstick.innerHTML=tickercontents[currentmessage]
    highlightmsg()
    }
    
    function highlightmsg(){
    var msgwidth=crosstick.offsetWidth
    if (clipwidth<msgwidth){
    clipwidth+=highlightspeed
    crosstick.style.clip="rect(0px "+clipwidth+"px auto 0px)"
    beginclip=setTimeout("highlightmsg()",20)
    }
    else{
    clipwidth=0
    clearTimeout(beginclip)
    if (currentmessage==tickercontents.length-1) currentmessage=0
    else currentmessage++
    setTimeout("changetickercontent()",tickdelay)
    }
    }
    
    function start_ticking(){
    crosstick=document.getElementById? document.getElementById("highlighter") : document.all.highlighter
    crosstickParent=crosstick.parentNode? crosstick.parentNode : crosstick.parentElement
    if (parseInt(crosstick.offsetHeight)>0)
    crosstickParent.style.height=crosstick.offsetHeight+'px'
    else
    setTimeout("crosstickParent.style.height=crosstick.offsetHeight+'px'",100) //delay for Mozilla's sake
    changetickercontent()
    }
    
    if (document.all || document.getElementById)
    window.onload=start_ticking
    
    </script>
    
    <p>This free script provided by<br />
    <a href="http://javascriptkit.com">JavaScript Kit</a></p>
        <!--end container--></div>
    </body>
    </html>
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •