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

查看:188
本文介绍了如何在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).

发生了什么?

推荐答案

但是animation.gif spinner在jQueryUI模态对话框中没有工作。有些浏览器很好,但是Firefox拒绝工作。去图形是什么原因然后发现这个超级优秀的非img旋转器组件。给所有的信用fgnass。



(注意:在这篇文章结尾处,我编辑了一个新的答案fix.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平板电脑firefoxbeta),Nokia Lumia800,Nokia 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 init函数中隐藏第一件事。然后,您可以随时显示+隐藏微调框,并随时播放动画。

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天全站免登陆