回答
如果必須使用CSS然後,給出下面的HTML,這是可能的(雖然有點麻煩):
<div id="timer">
<div class="interval"></div>
<div class="interval"></div>
<div class="interval"></div>
<div class="interval"></div>
</div>
而CSS:
@-moz-keyframes loading {
0%, 24% {
border-color: #f00;
}
25%, 100% {
border-color: #000;
}
}
@-ms-keyframes loading {
0%, 24% {
border-color: #f00;
}
25%, 100% {
border-color: #000;
}
}
@-o-keyframes loading {
0%, 24% {
border-color: #f00;
}
25%, 100% {
border-color: #000;
}
}
@-webkit-keyframes loading {
0%, 24% {
border-color: #f00;
}
25%, 100% {
border-color: #000;
}
}
@keyframes loading {
0%, 24% { /* stops the gradual fading-out */
border-color: #f00;
}
25%, 100% {
border-color: #000;
}
}
#timer .interval {
display: inline-block;
width: 1em;
height: 1em;
border: 1px solid #000;
border-radius: 50%;
-moz-animation: loading 20s linear infinite;
-ms-animation: loading 20s linear infinite;
-o-animation: loading 20s linear infinite;
-webkit-animation: loading 20s linear infinite;
animation: loading 20s linear infinite;
}
#timer .interval:nth-child(1) {
-moz-animation-delay: 0;
-ms-animation-delay: 0;
-o-animation-delay: 0;
-webkit-animation-delay: 0;
animation-delay: 0;
}
#timer .interval:nth-child(2) {
-moz-animation-delay: 5s;
-ms-animation-delay: 5s;
-o-animation-delay: 5s;
-webkit-animation-delay: 5s;
animation-delay: 5s;
}
#timer .interval:nth-child(3) {
-moz-animation-delay: 10s;
-ms-animation-delay: 10s;
-o-animation-delay: 10s;
-webkit-animation-delay: 10s;
animation-delay: 10s;
}
#timer .interval:nth-child(4) {
-moz-animation-delay: 15s;
-ms-animation-delay: 15s;
-o-animation-delay: 15s;
-webkit-animation-delay: 15s;
animation-delay: 15s;
}
或者,使用CSS過渡但使用JavaScript,在這種情況下的jQuery(爲簡單起見),到觸發下一個步驟,而不是手動使用,和設置,animation-delay
與CSS:
function transNext(currentEl, transitionClass) {
if (!currentEl) {
return false;
}
else {
transitionClass = transitionClass || 'interval';
var cur = $(currentEl),
nxt = cur.next().length ? cur.next() : cur.prevAll(':last');
cur.removeClass(transitionClass);
nxt.addClass(transitionClass);
}
}
$('#timer').on('mozAnimationEnd msAnimationEnd oAnimationEnd webkitAnimationEnd animationEnd', function(e) {
transNext(e.target, 'interval');
});
而修改後的CSS:
@-moz-keyframes loading {
0%, 99% {
border-color: #f00;
}
100% {
border-color: #000;
}
}
@-ms-keyframes loading {
0%, 99% {
border-color: #f00;
}
100% {
border-color: #000;
}
}
@-o-keyframes loading {
0%, 99% {
border-color: #f00;
}
100% {
border-color: #000;
}
}
@-webkit-keyframes loading {
0%, 99% {
border-color: #f00;
}
100% {
border-color: #000;
}
}
@keyframes loading {
0%, 99% { /* stops the gradual fading-out */
border-color: #f00;
}
100% {
border-color: #000;
}
}
#timer div {
display: inline-block;
width: 1em;
height: 1em;
border: 1px solid #000;
border-radius: 50%;
}
#timer .interval {
-moz-animation: loading 5s linear 1;
-ms-animation: loading 5s linear 1;
-o-animation: loading 5s linear 1;
-webkit-animation: loading 5s linear 1;
animation: loading 5s linear 1;
}
可以使用''setInterval'' JavaScript函數。看一下this JSFiddle here的例子,它可以工作。
HTML:
<div class="container">
<div class="marker"></div>
<div class="marker"></div>
<div class="marker"></div>
<div class="marker"></div>
</div>
CSS:
.marker {
background: #999;
float: left;
width: 20px;
height: 20px;
margin: 0 5px 0 0;
}
.marked {
border: 2px solid red;
}
的JavaScript:
jQuery(function() {
// Set border around first element
jQuery('.container .marker:first').addClass('marked');
// Start interval with 5 second steps
var iv = setInterval(function() {
// Executes every 5 seconds
// Is there a next element?
if (jQuery('.marker.marked').next('.marker').length == 1) {
jQuery('.marker.marked') // actual marked element
.removeClass('marked') // remove border
.next('.marker') // go to next element
.addClass('marked'); // add border
} else {
// No next element? Start again with first element
jQuery('.marker.marked').removeClass('marked');
jQuery('.container .marker:first').addClass('marked');
}
}, 5000);
});
從您的問題中不清楚您是否想從左到右進行一次運行,或者是否必須在序列中最後一張圖像之後的左側重新開始運行。我的例子在最後一個div後停止。你將不得不用你的圖像元素來替換DIV元素。他們只需要具有該類的「標記」屬性。
編輯:上面更新的小提琴/代碼循環遍歷元素,並重復第一個元素。
非常感謝你:) – user1833620
哦,忘了這個問題...如何使它不會停留在最後的div?它必須重複激活所有的時間......? – user1833620
我更新了代碼重複循環一次又一次。如果這是您想要的答案,請接受它作爲正確答案。 Thx :) – migg
- 1. 延遲從admob加載橫幅廣告
- 2. CSS動畫的延遲時間
- 3. JBoss啓動時間延遲
- 4. 基本CSS橫幅
- 5. 設置自動(延遲啓動)Windows服務的時間間隔
- 6. 處理環境 - 延遲時間延遲
- 7. Java時間延遲
- 8. Python時間延遲
- 9. JavaScript時間延遲
- 10. 時間延遲Tkinter
- 11. 頁面內容橫幅滾動(CSS)
- 12. CSS靜態背景橫幅
- 13. 在CSS中定位橫幅
- 14. HTML CSS橫幅對齊
- 15. 標題橫幅邊距css
- 16. 使用jQuery功能的CSS動畫有延遲時間
- 17. 延遲一段時間後自動啓動應用程序
- 18. 滾動橫幅tvOS
- 19. iOS Swipe Gesture - 滑動的時間延遲
- 20. 服務器啓動時間長延遲
- 21. jQuery動畫:時間延遲故障
- 22. 對焦動作的時間延遲
- 23. 推遲網頁安裝橫幅
- 24. 延伸到永遠的HTML橫幅
- 25. 「自動」與「自動(延遲啓動)」
- 26. 動畫之間的延遲
- 27. 啓動時延遲活動
- 28. 橫幅設置間隔
- 29. Memcache延遲時間太長?
- 30. 安卓時間延遲
你應該告訴我們你到目前爲止所做的嘗試,展示一些代碼,告訴我們你卡在哪裏。 – Jeroen