jquery自动刷新功能的问题

Issue with jquery auto refresh function

本文关键字:问题 新功能 刷新 jquery      更新时间:2023-09-26

我希望你们中的一个人可以为我指出正确的方向,关于我使用jquery auto_refresh函数的问题-下面的代码->嗯,它刷新和一切,但遗憾的是它看起来很丑。当刷新发生时,它不按比例闪烁。显然,一定有更顺畅的方法来做这件事……


<script>
var auto_refresh = setInterval(
function ()
{
$('#basic').load('resources_basic.php');
}, 1000);

$(function() {
$( "#draggable_res" ).draggable();
});
</script>

<div id="draggable_res" class="ui-widget-content">
<h5> Resources </h5>
  <div id="Accordion1" class="Accordion" tabindex="0">
    <div class="AccordionPanel">
      <div class="AccordionPanelTab">Basic Resources</div>
      <div class="AccordionPanelContent">
         <div id="basic"><?php include 'resources_basic.php'; ?></div>
      </div>
    </div>

<table width="160" border="2" cellspacing="2" cellpadding="2">
          <tr>
            <td width="30"><img src="images/product/gold.gif" width="30" height="30" alt="Gold" /></td>
            <td width="110"><?php echo $row_resourcesbasic_rs['gold']; ?></td>
          </tr>
          <tr>
            <td width="30"><img src="images/product/wood.gif" width="30" height="30" alt="Wood" /></td>
            <td width="110"><?php echo $row_resourcesbasic_rs['wood']; ?></td>
          </tr>
          <tr>
            <td width="30"><img src="images/product/clay.gif" width="30" height="30" alt="Clay" /></td>
            <td width="110"><?php echo $row_resourcesbasic_rs['clay']; ?></td>
          </tr>
          <tr>
            <td width="30"><img src="images/product/stone.gif" width="30" height="30" alt="Stone" /></td>
            <td width="110"><?php echo $row_resourcesbasic_rs['stone']; ?></td>
          </tr>
        </table>

褪色?这会使你的刷新更平滑

$('#basic').fadeOut('fast');
$('#basic').load('resources_basic.php',function(){
   $('#basic').fadeIn('fast'); 
});

显然,您需要为要添加动态数据的容器设置初始大小。否则,它将在每次加载和闪烁时调整大小。初始大小最好通过CSS设置,例如

#basic {
width: 100px;
height:100px;
background-color: #cccccc;
}

您可以链接淡出函数以获得更平滑的过渡:

var auto_refresh = setInterval(function (){
     $('#basic').fadeOut(500).load('resources_basic.php').fadeIn('fast');
}, 1000);