2011-07-19 87 views
2

使用下面的代码,我可以让对话框在AJAX数据加载时正确显示,但动画GIF不是动画 - 看起来非常糟糕。当我调用AJAX方法时,为什么我的动画GIF没有动画?

CSS:

.loading { 
    background: url('/images/loading.gif'); 
} 

的JavaScript:

$(function() { 
    $("#createButton").click(function(e){ 
     e.preventDefault(); 

     var $form = $(this).closest("form"); 

     $("#pleaseWait-dialog").dialog({ 
      modal: true, 
      height: 200, 
      resizable: false, 
      draggable: false 
     }); 

     $.ajax({ 
      type: "GET", 
      url: "myScript.cfm", 
      async: true, 
      success: function() { 
       $form.submit(); 
      } 
     }); 

     return false; 
    }); 
}); 

HTML:

<form action="post.cfm" method="post"> 
    <input 
     id="createButton" 
     type="submit" 
     name="createButton" 
     value="Create a New Thing" /> 
</form> 
<div id="pleaseWait-dialog" title="Gathering Data" style="display:none;"> 
    <span class="loading"></span> 
    <p>Thank you for your patience while we gather your data!</p> 
</div> 
+1

你的动画gif在哪里?我无法在任何地方看到对GIF的引用...如果您通过样式添加它,我不确定GIF是否会作为背景图片生成动画... – Chris

+0

GIF在CSS中(我添加了它以便澄清)。仅供参考,GIF作为背景图像生成动画。 –

回答

0

尽量展现它,当用户点击和Ajax请求结束后隐藏它。

$(function() { 
$("#createButton").click(function(e){ 
    $('#pleaseWait-dialog').show(); 
    e.preventDefault(); 

    var $form = $(this).closest("form"); 

    $("#pleaseWait-dialog").dialog({ 
     modal: true, 
     height: 200, 
     resizable: false, 
     draggable: false 
    }); 

    $.ajax({ 
     type: "GET", 
     url: "myScript.cfm", 
     async: true, 
     success: function() { 
      $form.submit(); 
     } 
    }); 

    return false; 
    }); 
}); 
2

这个问题只在IE浏览器中?看到这个页面关于IE导致动画GIF问题。表单提交完成后,您的动画gif可能会变得混乱。本页面将对此进行深入讨论。

http://www.stillnetstudios.com/animated-in-progress-indicator-for-long-running-pages/

一种解决方法是,以显示等待表单提交调用后。当然,如果您的AJAX呼叫需要很长时间才能处理,您的用户将不知道发生了什么。

+0

感谢您的信息 - 我目前正在IE中测试。表单提交后显示加载器的结果相同。总的来说,我希望用户知道正在做的事情,可能需要几秒钟,所以他们不会吓坏了,并刷新,等等。 –

0

要重新开始动画,请将图像的src属性设置为其当前值。

See this answer代码使用超时在几毫秒后重新启动动画。

0

为了使其在IE中工作插入与gif里面的iframe,听起来很疯狂,但工程。

相关问题