PDA

View Full Version : Stop / Start a marquee with a button?



Chimbo
11-11-2011, 03:36 PM
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

jscheuer1
11-11-2011, 05:05 PM
Here's one way:


<!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>

Chimbo
11-17-2011, 05:07 PM
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.