2013-03-06 47 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>