我試圖在我公司的ERP中創建通知系統,類似於Facebook。現在,工作幾個小時後,它看起來像這樣:我試圖讓它閃爍,但它不會工作
每個菜單項是li
元素。每個元素都有的,將修改它的類人的背景色:
selected
是藍色的,在圖片上restricted
顯示爲紅色現在
,我想要實現的是以使li
背景在某些事件上閃爍(當新消息進來並且列表未打開(並且selected
類不存在))。
問題是:它不會閃爍。 :(
這裏是我的HTML(不包括信息框)的卡扣
<li class="notifications-topmenu-button selected">
<a href="#">
<div class="notifications-topmenu-button-wrapper">
<div class="notifications-topmenu-button-icon">
<img class="transparent" width="13" height="13" align="absmiddle" src="/images/icons/notifications.png" title="Powiadomienia" alt="Powiadomienia">
</div>
<div class="notifications-topmenu-button-counter" style="display: block;">3</div>
</div>
</a>
<span class="divider"> : </span>
</li>
<li class="selected">
<a href="/system_dev.php/users/profile">Strona główna</a>
<span class="divider"> : </span>
</li>
此外,還有一些JavaScript啓動對象(不介意評論):
function notificationsObject(){
var nl = new Object();
//atrybuty klasy
nl.liElement = $('.notifications-topmenu-button');
nl.menuButton = $('.notifications-topmenu-button-wrapper');
nl.menuButtonCounter = nl.menuButton.find('.notifications-topmenu-button-counter');
nl.notificationsCount = jQuery.trim(nl.menuButtonCounter.text());
nl.notificationsList = $('.notifications-list-wrapper');
nl.blinkingInterval = null;
nl.startBlinking = function(){
nl.blinkingInterval = setInterval(function(){
if(nl.liElement.hasClass('restricted') == false){
console.debug(nl.liElement.addClass('restricted'));
}
else {
nl.liElement.removeClass('restricted');
}
}, 1000);
}
nl.stopBlinking = function(){
if(nl.blinkingInterval != null) nl.blinkingInterval = null;
}
(more 'class' functions)
return nl;
}
我們測試它,我只是打電話
$(document).ready(function(){
var notifications = notificationsObject();
notifications.startBlinking();
});
當然我在函數聲明後調用它
有趣的是,當我改變nl.startBlinking
函數setInterval
內部只添加restricted
類,它的工作原理。我很肯定它肯定是一些錯字或愚蠢的錯誤,但我找不到它。
請幫忙!
不要認爲這是它,它不是一個「即時功能」,你只能稱它一次。這裏是另一個帶有console.log('started')的小提琴,以顯示它只被調用一次http://jsfiddle.net/w9SDH/。很高興你把它分類。 – Ben 2013-03-26 09:34:09
不要忘記接受你的答案(如果可以的話)以備將來參考。 – zik 2013-03-26 11:24:29
本 - 這是真的。事實上,這個問題在其他地方說謊。更進一步,在我的'notificationObject()'函數中,我做了一些與'construct'類似的東西 - 只是一組在啓動時執行的函數。其中一個是檢查通知計數是否大於0,然後更改頁面標題並執行閃爍。這是我愚蠢的錯誤,但說實話,無論如何,你們幫我找到了它。謝謝! – ex3v 2013-03-26 13:56:15