Hhml 標題 閃爍

1.添加一個jq擴展

   <script type="text/javascript">
         (function ($) {
            $.extend({
                /**
                * 调用方法: var timerArr = $.blinkTitle.show();
                *            $.blinkTitle.clear(timerArr);
                */
                blinkTitle: {
                    show: function () {    //有新消息时在title处闪烁提示
                        var step = 0, _title = document.title;
                        var timer = setInterval(function () {
                            step++;
                            if (step == 3) { step = 1 };
                            if (step == 1) { document.title = '【   】' + _title };
                            if (step == 2) { document.title = '【新消息】' + _title };
                        }, 500);
                        return [timer, _title];
                    },
                    /**
                    * @param timerArr[0], timer标记
                    * @param timerArr[1], 初始的title文本内容
                    */
                    clear: function (timerArr) {    //去除闪烁提示,恢复初始title文本
                        if (timerArr) {
                            clearInterval(timerArr[0]);
                            document.title = timerArr[1];
                        };
                    }
                }
            });
        })(jQuery);

2.方法調用

        jQuery(function ($) {
            var timerArr = $.blinkTitle.show();
            setTimeout(function () {        //此处是过一定时间后自动消失
                $.blinkTitle.clear(timerArr);
            }, 10000);
            //若认为操作消失,只需如此调用:    $.blinkTitle.clear(timerArr);
        });

3.說明

    其實是定時,換html 的title的內容。

posted @ 2012-03-05 13:32  無限遐想  阅读(454)  评论(0编辑  收藏  举报