dongta5621 2011-10-29 09:20
浏览 17
已采纳

当用户在不同的选项卡上或离开时,突出显示新的聊天ping <div>

I recently created a custom ping box (chat). I have a auto refresh every 3 seconds to get the latest content.

If the user is busy anywhere other than the chat tab, I would like the latest chat pings to be highlighted in some different color.

This would allow the user to easily identify the latest pings that came in when they weren't on the tab. The color then fades automatically after 10 sec of coming into the chat tab.

Code to refresh new content:

    function loadNewPosts(){
        var id = $(".altbgcolor:first").attr("id");

        $.post('/updateping.php', { updateid: id }, function(data){
                                $(".newslist").prepend(data);
                                //alert(data);
                            }, 'html');
        }

     window.setInterval(loadNewPosts, 1000*3)   

Is it possible to code this using PHP and/or jQuery?

  • 写回答

1条回答 默认 最新

  • download1002 2011-10-29 09:32
    关注

    You need to use the blur event of the window to change the class of the divs created out of focus.

    Like this:

    $(window).blur(function() {
        //Toggle ALL newly created divs to have a unique CSS class
        //For this example lets call it "outOfFocus"
    });
    

    Then when the window comes back into focus use jqueryUI's highlight effect

     $(window).focus(function() {
         $(".outOfFocus").effect("highlight", {}, 10000);
         //Toggle all newly created divs to have the normal "inFocus" CSS class  
    
    }); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献