我正在用Javascript/PHP創建簡單的聊天。例如,當我在Facebook上發佈新消息時,我想閃爍/眨眼選項卡。我怎樣才能做到這一點?Javascript中的Flash/blink選項卡效果
-2
A
回答
2
下面是示例代碼:
(function() {
var original = document.title;
var timeout;
window.coders = function (newMsg, howManyTimes) {
function step() {
document.title = (document.title == original) ? newMsg : original;
if (--howManyTimes > 0) {
timeout = setTimeout(step, 1000);
};
};
howManyTimes = parseInt(howManyTimes);
if (isNaN(howManyTimes)) {
howManyTimes = 5;
};
cancelcoders(timeout);
step();
};
window.cancelcoders = function() {
clearTimeout(timeout);
document.title = original;
};
}());
您可以使用此代碼類似:
coders("New Message from Bhavin Solanki");
......或者......
coders("New Message from Bhavin Solanki", 20); // toggles it 20 times.
+0
非常感謝你,但爲什麼我的問題有3分鐘? –
+0
不知道...可能是某些評論者因某種原因已經放棄投票。 –
+0
如果我的答案適合你,你可以放棄並接受它 –
0
你最好在CSS中執行動畫,並使用JavaScript來啓動和停止動畫。你因爲沒有表現出解決方案的嘗試而陷入低谷。
(function(){
var message = document.querySelector('.message'),
button = document.querySelector('#button');
button.addEventListener('click', blink, false);
// this is where you toggle the class
function blink(e){
message.classList.toggle('blink');
}
})();
@keyframes blink {
from {
background-color: red;
color: white;
}
to {
background-color: white;
color: red;
}
}
.message {
text-align: center;
}
/* run the animation on .message when it also has the class .blink */
.message.blink {
animation: blink 1s linear infinite alternate;
}
<div class="message">You've got a message</div>
<button id="button">blink</button>
相關問題
- 1. 選項卡上的懸停效果
- 2. 管理選項卡及其效果
- 3. WPF Tabcontrol:對選項卡項目選擇滑動效果
- 4. 如何禁用jQuery選項卡中的顯示效果?
- 5. Qt:Hower效果與選定的選項卡重疊
- 6. 如果上述選項卡中選擇
- 7. 合併選項卡中的選項卡
- 8. 從導航/選項卡欄中刪除光澤/漸變效果
- 9. 在新選項卡中的javascript window.location
- 10. iOS的滑動效果ViewControllers - Instagram的活動選項卡
- 11. 在選項卡上的jQuery循環效果
- 12. 爲選項卡式內容添加不錯的滑動效果
- 13. jQuery的工具選項卡淡入淡出效果
- 14. Android市場選項卡沒有分段的效果
- 15. 切換選項卡JavaScript
- 16. Javascript選項卡式搜索框選項卡highlighing
- 17. 刪除默認選項卡選項,並添加滾動到效果
- 18. 如何在Internet Explorer的選項卡容器中使用javascript更改選項卡
- 19. 在Access 2007中的選項卡外部選項卡上的選項卡
- 20. jQuery選項卡和滑動效果 - 不一起工作
- 21. Ajax選項卡淡入淡出效果問題 - jQuery工具
- 22. jQuery選項卡旋轉效果除了切換?
- 23. jQuery-UI選項卡 - 如何更改效果?
- 24. 如何在jQueryUI選項卡上實現滑動效果
- 25. 如何將JavaScript函數的結果加載到新選項卡
- 26. JavaScript選項卡 - 如果控制它的函數太多
- 27. WPF - 選項卡控件中的兩行選項卡 - 選項卡包裝
- 28. Jquery選項卡選中沒有選項卡被選中
- 29. Android:選項卡內的選項卡
- 30. 將引人注目的選項卡更改爲引導效果中的滾動
瀏覽器選項卡?嘗試這樣的:http://stackoverflow.com/a/24025860/2278598 –
開始寫一些代碼,並嘗試一些東西。 – csmckelvey
也許你是對的,但我沒有任何想法做到這一點。現在,我知道了。 –