如何在 IE 的 jQuery 对话框中显示动画 GIF? [英] How do you display animated GIFs within a jQuery Dialog in IE?

查看:20
本文介绍了如何在 IE 的 jQuery 对话框中显示动画 GIF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有以下代码,似乎在除 IE 之外的所有浏览器中都能正常工作:

We have the following code which seems to work just fine in every browser except IE:

var d = $('<img src="spinner.gif"/>');
d.dialog({modal:true});

在 IE 中它似乎工作得很好,只是微调器不旋转(它是一个动画 GIF).

In IE it seems to work just fine except the spinner doesn't spin (it's an animated GIF).

发生了什么事?

推荐答案

我尝试了 "everything" 但 animation.gif 微调器在 jQueryUI 模态对话框中不起作用.有些浏览器很好,但 Firefox 拒绝工作.去看看是什么原因.然后发现了这个超级优秀的非img spinner组件.将所有学分归于 fgnass.

(注意:在这篇文章的最后,我编辑了一个新的答案来修复动画.gif 问题)

I tried "everything" but animation.gif spinner did not work in jQueryUI modal dialog box. Some browsers were fine but it was Firefox refusing to work. Go figure whats the reason. Then found this super excellent non-img spinner component. Give all credits to fgnass.

(NOTE: At the end of this post I have edited a new answer fixing animation.gif problem)

http://fgnass.github.com/spin.js/

http://twitter.com/fgnass

// Show loading(processing) modal dialog
function showLoading(sTitle, str) {
    if (sTitle==undefined) sTitle = "Processing";
    if (str==undefined) str = "Processing...";
    var strBody = "<div id='spinnerdiv'><div style='padding-left:35px'>" + str + "</div></div>";

    $("#uidialog").html(strBody);   
    $("#uidialog").dialog({
        title: sTitle,
        modal: true, resizable: true, width: "auto", height: "auto",
        close: function(event, ui) { },
        buttons: {
            "Close": function() {
                $(this).dialog("close");
            }
        }
    });

    // must use css spinner, animated gif did not work in every browser
    var opts = {
        lines: 11, length: 7, width: 3, radius: 4, corners: 1,  rotate: 0, 
        color: '#000', speed: 0.7, trail: 38, shadow: false,  hwaccel: true, 
        className: 'spinner', zIndex: 2e9, top: '0', left: '0'
    };
    var target = document.getElementById("spinnerdiv");
    var spinner = new Spinner(opts).spin(target);   
}

我运行过 Firefox、IE8、Chrome、Opera、Android 平板电脑(stock 和 firefoxbeta)、诺基亚 Lumia800、诺基亚 C7 浏览器.一切正常.

I have run Firefox, IE8, Chrome, Opera, Android tablet (stock and firefoxbeta), Nokia Lumia800, Nokia C7 browsers. All works fine.

编辑 1(使用 gif 动画) 这就是我能够修复在某些浏览器上没有动画的 spinner.gif 的方法.技巧是在 html 页面加载时保持微调器 div 的可见状态.首先在 jQuery 初始化函数中隐藏它.然后,您可以随时显示+隐藏微调器 div 及其动画.

Edit 1 (use gif animation) This is how I was able to fix spinner.gif not animated on some browsers. Trick is to keep spinner div visible state at html page load. Hide it first thing in the jQuery init function. Then you may show+hide spinner div anytime you like and its animated.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>Spinner Test</title>
  <script src="jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(function($) {
    var spinner = $("#spinner");
    spinner.hide();
    $("#btnShow").click(function() { onShowClicked(); return false; });
    $("#btnHide").click(function() { onHideClicked(); return false; });
});

function onShowClicked() {
    var spinner = $("#spinner");
    spinner.show();
}

function onHideClicked() {
    var spinner = $("#spinner");
    spinner.hide();
}
</script>
</head>
<body>

<a href="" id="btnShow">SHOW</a> &nbsp;&nbsp; <a href="" id="btnHide">HIDE</a>

<br/><br/>
<div id="spinner"><img src="loader.gif" /></div>

</body>
</html>

这篇关于如何在 IE 的 jQuery 对话框中显示动画 GIF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆