【问题标题】:jquery load interval div flashjquery加载间隔div flash
【发布时间】:2012-10-27 13:55:43
【问题描述】:

所以,我有一个使用以下代码的 div,但它在重新加载时会闪烁。我知道 1000 是荒谬的——它只是在我测试时设置的。有没有办法避免“flash”,就好像那个 div 是一个页面重新加载一样?

非常感谢!

<script type="text/javascript">
    $(document).ready(function(){
    $("#timelinerContainers").load("jquery_timeline.php");
       var refreshId = setInterval(function() {
          $("#timelinerContainers").load('jquery_timeline.php');
       }, 1000);
       $.ajaxSetup({ cache: false });
    });
</script>

如果我点击页面上的任何地方,它就会停止闪烁...相当奇怪。

非常感谢您的帮助!!!

【问题讨论】:

    标签: php jquery sql css html


    【解决方案1】:

    你试过了吗

    $("#timelinerContainers").fadeOut().load('jquery_timeline.php').fadeIn();
    

    $("#timelinerContainers").fadeOut().load('jquery_timeline.php',function(){
        $(this).fadeIn()
    });
    

    【讨论】:

    • 这只是将其更改为淡入/淡出。问题是它在执行数据库查询时完全重新加载 div 的时间间隔。这很好,但它会导致“消失”......“重新出现”。这是我试图避免的,这就像一次硬刷新。我想避免这种情况?
    【解决方案2】:

    试试这个代码:

    <script type="text/javascript">
        $(document).ready(function(){
            $.ajaxSetup({ cache: false });
            $.ajax({
                url: "jquery_timeline.php",
                success: function(data) {
                    $("#timelinerContainers").html(data);
                }
            });
        });
    </script>
    

    变化是我使用了jQuery.ajax() 函数来加载内容。我在这里所做的是在发出ajax请求之前先加载内容然后更新div,而不是清除内容。

    【讨论】:

      猜你喜欢
      • 2017-10-31
      • 1970-01-01
      • 2011-03-22
      • 2011-07-01
      • 1970-01-01
      • 2011-07-12
      • 1970-01-01
      • 1970-01-01
      • 2012-05-20
      相关资源
      最近更新 更多