2013-03-06 44 views
4

我使用下面的HTML代码段水平滚动文本:HTML/JavaScript:如何停止选取框加载,并启动鼠标悬停?

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

我是,一旦你访问该页面时,marquee开始自动滚动的问题。我想要做的是冻结marquee,直到你mouseover。

+0

我不知道,但我会这样做的方式不会与选取框标记,我会使用动画来移动文本。 – 2013-03-06 11:30:56

+0

您需要在加载时明确停止它。 – feeela 2013-03-06 11:31:37

回答

1

您可以用scrollAmount修补,而不是调用start()和stop(),以及刚刚成立scrollamount 0开始。例如。

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

http://jsfiddle.net/svt9L/

注意,这是一个直接回答你的问题。不过,我完全赞同Jon P的回答。有比使用选取框元素更好的解决方案。

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

<body onload="document.getElementById('myMarquee').stop();"> 
+0

Thx!当鼠标悬停时,是否可以重置选取框? – 2013-03-06 11:36:45

10

我要健全居高临下这里...

其2013年The marquee tag is dead. It is browser specific. It is just plain wrong and was a mistake to begin with.

在一个应该使用HTML定义内容语义化的HTML的新时代。视觉样式应该与CSS和视觉效果一起应用,如果需要,用CSS补充。

请参阅this article了解现代方法的双向概述。

也有纯CSS3的方法:http://www.hongkiat.com/blog/css3-animation-advanced-marquee/

,可能最适合您的产品:Javascript(和jQuery)解决方案:http://remysharp.com/2008/09/10/the-silky-smooth-marquee/注意:链接解决方案中的示例使用选取框标记,但不限于使用选取框标记。你可以使用任何有效的jquery选择器。

1

尝试其中之一。

<!-- MOVING UP --> 
<marquee direction="up" onmouseover="this.setAttribute('scrollamount', 0, 0);" onmouseout="this.setAttribute('scrollamount', 6, 0);"></marquee> 

<!-- MOVING DOWN --> 
<marquee direction="down" onmouseover="this.setAttribute('scrollamount', 0, 0);" onmouseout="this.setAttribute('scrollamount', 6, 0);"></marquee> 

<!-- MOVING LEFT --> 
<marquee direction="left" onmouseover="this.setAttribute('scrollamount', 0, 0);" onmouseout="this.setAttribute('scrollamount', 6, 0);"></marquee> 

<!-- MOVING RIGHT --> 
<marquee direction="right" onmouseover="this.setAttribute('scrollamount', 0, 0);" onmouseout="this.setAttribute('scrollamount', 6, 0);"></marquee>