【问题标题】:display 'loading' at the beginning of a function not working/happens too fast在功能不工作/发生太快的开头显示“正在加载”
【发布时间】:2011-10-13 10:29:11
【问题描述】:

我有这样的表达方式:

$('#animationNext,#animationPrev').bind('mousedown',function(){        
    $('.nInfoIE').show();
    $('ul.roundabout-holder li').find('.iframe').css({'visibility':'hidden'});
    $('ul.roundabout-holder li').find('.iframe').addClass('esconder');

    // more code...

    watching = false;
    $('.nInfoIE').hide();
});

请注意我在问题中删除了许多表达式。

情况是这在所有浏览器中都很好用,但在 IE6 中它需要 10 倍 loger 才能执行(我说的是 7 秒左右!)所以我试图在开头显示 <div class="nInfoIE">(包含一个 loding 图像)并在最后隐藏它,

但是好像都是同时执行的什么的,因为我永远看不到nInfoIe的内容,

我如何确保我会在之前看到它,然后执行其余的?

-EDIT-html代码:

<ul class="roundabout-holder" style="padding: 0px; position: relative; z-index: 100;">
    <li class="roundabout-moveable-item roundabout-in-focus" style=
    "position: absolute; left: 157.2px; top: -0.8px; width: 240px; height: 160px; opacity: 1; z-index: 400; font-size: 16px;"
    current-scale="1.0000">
      <a href="#" title="video#1"><img src="http://img.youtube.com/vi/qZ9jpnMGkdA/0.jpg"
      class="thumbImg"><img alt="video#1" class="playIcon" src=
      "img/playIcon.png"><span class="titulo titThumb">video#1</span></a>

      <div class="iframe esconder">
        <iframe width="560" height="315" frameborder="0" allowfullscreen="" src=
        "http://youtube.com/embed/qZ9jpnMGkdA"></iframe>
      </div><span class="titulo titIframe">video#1</span>
    </li>

    <li class="roundabout-moveable-item" style=
    "position: absolute; left: -58.8px; top: 23.2px; width: 168px; height: 112px; opacity: 0.7; z-index: 250; font-size: 11.2px;"
    current-scale="0.7000">
      <a href="#" title="video#2"><img src="http://img.youtube.com/vi/hurnoKLuBD8/0.jpg"
      class="thumbImg"><img alt="video#2" class="playIcon" src=
      "img/playIcon.png"><span class="titulo titThumb">video#2</span></a>

      <div class="iframe esconder">
        <iframe width="560" height="315" frameborder="0" allowfullscreen="" src=
        "http://youtube.com/embed/hurnoKLuBD8"></iframe>
      </div><span class="titulo titIframe">video#2</span>
    </li>

    <li class="roundabout-moveable-item" style=
    "position: absolute; left: 229.2px; top: 47.2px; width: 96px; height: 64px; opacity: 0.4; z-index: 100; font-size: 6.4px;"
    current-scale="0.4000">
      <a href="#" title="video#3"><img src="http://img.youtube.com/vi/Lk_WoaLUPdA/0.jpg"
      class="thumbImg"><img alt="video#3" class="playIcon" src=
      "img/playIcon.png"><span class="titulo titThumb">video#3</span></a>

      <div class="iframe esconder">
        <iframe width="560" height="315" frameborder="0" allowfullscreen="" src=
        "http://youtube.com/embed/Lk_WoaLUPdA"></iframe>
      </div><span class="titulo titIframe">video#3</span>
    </li>

    <li class="roundabout-moveable-item" style=
    "position: absolute; left: 445.2px; top: 23.2px; width: 168px; height: 112px; opacity: 0.7; z-index: 250; font-size: 11.2px;"
    current-scale="0.7000">
      <a href="#" title="video#4"><img src="http://img.youtube.com/vi/m5ykAFtQgQ0/0.jpg"
      class="thumbImg"><img alt="video#4" class="playIcon" src=
      "img/playIcon.png"><span class="titulo titThumb">video#4</span></a>

      <div class="iframe esconder">
        <iframe width="560" height="315" frameborder="0" allowfullscreen="" src=
        "http://youtube.com/embed/m5ykAFtQgQ0"></iframe>
      </div><span class="titulo titIframe">video#4</span>
    </li>
  </ul>

【问题讨论】:

    标签: jquery internet-explorer-6 method-chaining execution-time


    【解决方案1】:

    我只能假设“更多代码”部分适用于一个或多个 ajax 请求。 ajax 请求被触发后,即使 ajax 请求尚未完成,也会处理下一个表达式。您应该在 ajax 请求的完成事件中隐藏加载图像。

    $.ajax({
      type: 'POST',
      url: url,
      data: data,
      success: success,
      complete: function() { watching = false;
                        $('nInfoIE').hide(); }
    });
    

    如果有多个 ajax 请求会变得有点复杂,您必须嵌套它们或使用某种 ajax 队列管理器。

    【讨论】:

    • 没有 ajax 请求。仅通过 JS 进行 Css 和 HTML 操作
    • 那很奇怪,在完成所有操作之前不应该隐藏图像。在那种情况下,我不禁想知道图像是否会出现。如果您省略对 hide() 的调用,它是否只是停留在屏幕上?
    • 就是这样。图像根本不显示。问题是我省略的代码 - 没有 ajax 但是 - 在 IE6 中执行需要很长时间。所以我想在执行开始时显示它并在最后隐藏它,但甚至看不到它:S
    • 可能是css的问题,也可能是html结构的问题,需要查看html包含相关css的图片元素才能做出更好的判断。
    【解决方案2】:

    好吧,您提供了代码,但我看不到任何类名为“nInfoIE”的元素,这在此处有点相关。

    但是,我确实注意到了您的选择器:

    $('nInfoIE').show();
    

    由于您试图通过类名获取元素,因此您必须指定“。”在它面前。应该是

    $('.nInfoIE').show();
    

    【讨论】:

    • 谢谢我已经看到了这个错误,但仍然没有解决问题。 div 是同时播种和隐藏的——或者看起来就是这样——
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-15
    • 1970-01-01
    相关资源
    最近更新 更多