我使用CSS3動畫創建選取框效果。這是我的代碼。CSS3選取框效果
HTML標籤:
<div id="caption">
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. the quick brown fox jumps over the lazy dog.
</div>
CSS:
#caption
{
position: fixed;
bottom: 0;
left: 0;
font-size: 20px;
line-height: 30px;
height:30px;
width: 100%;
white-space: nowrap;
-moz-animation: caption 50s linear 0s infinite;
-webkit-animation: caption 50s linear 0s infinite;
}
@-moz-keyframes caption { 0% { margin-left:120%; } 100% { margin-left:-4200px; } }
@-webkit-keyframes caption { 0% { margin-left:120%; } 100% { margin-left:-4200px; } }
現在我可以得到基本的字幕效果,但這些代碼並不明智不夠。
我不知道是否有辦法避免使用像margin-left:-4200px;
這樣的特定值,以便它可以適應任何長度的文本。
此外,它在Firefox和Safari中執行得並不順利,在Chrome中表現良好。
這是一個類似的演示:http://jsfiddle.net/jonathansampson/XxUXD/,它使用text-indent
但仍具有特定的值。
任何意見將不勝感激。
Fred
+1翻譯可能是最乾淨的解決方案! – Christoph
正是我想要的,那會更加靈活,非常感謝你。 –
當我在我的網站上嘗試時,這並不適用於我。我發現有一個需要的外部資源[prefixfree.js](http://leaverou.github.io/prefixfree/prefixfree.js)。我應該注意到(1)在jsfiddle頁面的外部資源旁邊。對於那些沒有去那裏複製上述文本的人,您還需要前綴自由的JavaScript文件。 – Recognizer