douyu1656 2013-05-16 17:48
浏览 38

MYSQL列每5秒选择并附加一个像文本流一样的div

I'm trying to accomplish an effect of a smooth river like flow of text that is inserted in to the MySQL backend.

Let me explain a bit more with some code.

MySQL Table_Logs

id | logs  
1  | Testing 1  
2  | Testing 2  
3  | Testing 3  
4  | Testing 4  
5  | Testing 5
6  | Testing 6    

What I'm trying to accomplish is to have a jquery function as shown below query this Table_logs every 5 seconds and display any new log it has. The logs should only show the last 5 records from the newest being at the top and the bottom fading out as a new one is appended on top.

I learned that I need to start my Javascript with something similar to below

window.setInterval(function(){
   $.get('/update.php' function(data){
   var output = '<span class="logs_style">'+data+'</span>'
   $("#logs").append(output );
   }, 'html');
}, 5000);

What I would like the output to look like in HTML is as follows

<div id="logs">
   <span class="logs_style">Testing 6</span>
   <span class="logs_style">Testing 5</span>
   <span class="logs_style">Testing 4</span>
   <span class="logs_style">Testing 3</span>
   <span class="logs_style">Testing 2</span>
</div>

Can anyone assist me on how I can go about this? Thank you for reading and any help would be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • dpxbc88022 2013-05-16 17:54
    关注

    You could fade out the last item and fade in the new one

    window.setInterval(function(){
    $.get('/update.php' function(data){
    var $output = $('<span class="logs_style" style="display:none">'+data+'</span>');
    $("#logs").append($output);
    $("#logs").last().fadeOut(function(){
        $output.fadeIn();
    });
    }, 'html');
    }, 5000);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b