Results 1 to 3 of 3

Thread: Stop / Start a marquee with a button?

  1. #1
    Join Date
    Sep 2011
    Location
    MD
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Stop / Start a marquee with a button?

    I'm wondering if it's possible to do this with JavaScript:

    I want to be able to start a rather long
    <marquee> oh gosh this is looooong</marquee> from the very beginning,
    if any visitor wishes to do so.

    Please tell me how I would code that into a button that the web page visitor could press?

    Thanks

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Here's one way:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title>Restar Marquee - Demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css">
    marquee {
    	width: 550px;
    }
    </style>
    <script type="text/javascript">
    function restartmarq(){
    	var marq = document.getElementsByTagName('marquee')[0];
    	marq.stop();
    	marq.parentNode.replaceChild(restartmarq.marq.cloneNode(true), marq);
    }
    function grabmarq(){
    	restartmarq.marq = document.getElementsByTagName('marquee')[0].cloneNode(true);
    }
    if (window.addEventListener){
    	window.addEventListener('load', grabmarq, false);
    }
    else if (window.attachEvent){
    	window.attachEvent('onload', grabmarq);
    }
    </script>
    </head>
    <body>
    <marquee>Her leering backers chaotically heap up a reassuring universalist. The curious bachelors enthusedly afford little for an arrogant banshee. That puzzled turtle hardly amuses the lilting beagles. Your approving unicorns guiltlessly memorize the scrawny bongos. Your smoggy bakers enthusiastically annoy those scowling tongues. Our brave aces adversarially alert the quaint aardvarks. Your quarrelsome whales cheerlessly apologize for a loving acre. Your absorbing families acutely analyze a black aspersion. The cultured blocks credulously heat those quaking turtledoves. Your mincing tirades deftly admire the ancient animals. </marquee>
    <br><input type="button" value="Restart" onclick="restartmarq();">
    </body>
    </html>
    Last edited by jscheuer1; 11-11-2011 at 07:00 PM. Reason: minor code improvement
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Sep 2011
    Location
    MD
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    John,

    Thanks, that works well.
    I will take a risk at bugging you further, and ask if there isn't away to make the button part of the function an "invisible-until-needed" sort of function, where it or any small graphic or label will pop up, only when the user's mouse is over the scrolling marquee.

    But, if so, I imagine " <input . . . " function would have to be turned into even more code, or something.

    And by the way, thanks for pointing me to my original post, which I'd forgotten.


    bowing my head now, in humbled shame.

Bookmarks

Posting Permissions

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