Search code examples
javascripthtmlscrollmouseovermarquee

HTML/JavaScript: How to stop marquee onload, and start on mouseover?


I'm using the following HTML piece of code to scroll text horizontally:

<marquee behavior="scroll" direction="left" onmouseover="this.start();" onmouseout="this.stop();">Go on... hover over me!</marquee>

The issue I have is that once you visit the page, the marquee starts scrolling automatically. What I want to do, is to freeze the marquee until you mouseover.


Solution

  • You could tinker with scrollAmount instead of calling start() and stop(), and just set scrollamount to 0 initially. E.g.

    <marquee behavior="scroll" direction="left" scrollamount="0" onmouseover="this.scrollAmount = 6" onmouseout="this.scrollAmount = 0">Go on... hover over me!</marquee>

    See http://jsfiddle.net/svt9L/

    Note that this is a direct answer to your question. However I fully endorse Jon P's answer. There are better solutions available than using the marquee element.