将鼠标悬停在Pause Marquee上

时间:2011-09-17 04:19:54

标签: javascript jquery html css marquee

我想创建一个滚动一些新闻文章的Marquee,但是当用户将鼠标悬停在它上面时,我需要它暂停,当用户将其悬停时(onMouseOut)我需要重新启动。这不起作用:

<marquee onMouseOver="this.stop()" onMouseOut="this.start()">Text</marquee>

有没有人对如何用最少量的代码实现这一目标有任何建议?

7 个答案:

答案 0 :(得分:29)

<marquee onmouseover="this.stop();" onmouseout="this.start();">
my text here
</marquee>

您使用的是错误的案例:onMouseOver,onMouseOut

答案 1 :(得分:17)

我只是在欢呼这个狂欢,因为我没有看到任何人在YEARS中使用marquee标签

不得不查找它,但是marquee标签有一个名为“scrollamount”的属性,它可以控制它的速度。所以我们需要做的就是当我们悬停时将值设置为0,并在我们鼠标移出时将其设置为5.

DEMO:http://jsfiddle.net/U9yFj/

$(function() {
    $('marquee').mouseover(function() {
        $(this).attr('scrollamount',0);
    }).mouseout(function() {
         $(this).attr('scrollamount',5);
    });
});

我希望我为此付出疯狂的支持

答案 2 :(得分:4)

<marquee behavior="scroll" scrollamount="5" direction="left" onmouseover="this.setAttribute('scrollamount',0);" onmouseout="this.setAttribute('scrollamount',5);">
 Your name, your address, your details scrolling through line
</marquee>

希望此代码可以帮助使用MARQUEE标记的人。

答案 3 :(得分:2)

<marquee id="mq" direction="right" loop="true" onmouseover="this.stop();" onmouseout="this.start();">
    <a href="http://google.com">Google</a>
    <input type="text" id="txt" />
    <input type="button" id="btn" value="Click here" onclick="alert(txt.value);" />
    Some other text here</marquee>

答案 4 :(得分:1)

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

答案 5 :(得分:0)

您只需使用

的HTML选框标记即可
onmouseover="stop()"

接着是

onmouseout="start()"

答案 6 :(得分:0)

关闭;后,您必须在代码中添加()