Javascript 悬停以暂停选框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7452398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 02:21:24  来源:igfitidea点击:

Hover Over to Pause Marquee

javascriptjqueryhtmlcssmarquee

提问by Howdy_McGee

I want to create a Marquee that scrolls some news articles but when the user hovers over it I need it to pause and when the user hovers out of it (onMouseOut) I need to ti start back up. This did not work:

我想创建一个滚动一些新闻文章的选框,但是当用户悬停在它上面时我需要它暂停,当用户悬停在它外面 (onMouseOut) 时我需要重新开始。这不起作用:

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

Does anyone have any suggestions on how I can achieve this in a minimal amount of code?

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

回答by Leo

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

You're using wrong case: onMouseOver,onMouseOut

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

回答by wesbos

The marquee tag has an attribute called scrollamountwhich controls how fast it goes. All we need to do is set the value to 0when we hover in and set it back to 5when we mouse out.

marquee 标签有一个名为的属性scrollamount,用于控制它的运行速度。我们需要做的就是将0鼠标悬停时的值设置为,并在鼠标移开时将其设置回5

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

演示:http: //jsfiddle.net/U9yFj/

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

回答by Fadi

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

回答by Abbas

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

Hope this code will help someone who is use MARQUEE tag.

希望这段代码能帮助那些使用 MARQUEE 标签的人。

回答by Nipek

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

回答by Jiwan

You can simply use the HTML marquee markup with

您可以简单地使用 HTML 选框标记

onmouseover="stop()"

followed by

其次是

onmouseout="start()"

回答by RAHUL RAWAT

You have to add ;to your code after closing the ().

你必须添加;在关闭后,你的代码()