简体   繁体   English

Chrome:JQuery动画; 仅在开发人员工具中选择后才似乎起作用

[英]Chrome: JQuery animate; only appears to work when selected in developer tools

I have some styled pages I need to get working. 我需要一些样式化的页面才能开始工作。 A loading bar is a part of the pages. 加载栏是页面的一部分。 The loading bar is to appear when the page is navigated away from (as the back end can take some time to respond). 当页面离开页面时,将显示加载栏(因为后端可能需要一些时间才能做出响应)。 After appearing the loading bar then needs to 'load' whilst the visitor is awaiting the next page. 出现加载栏后,需要在访客等待下一页时“加载”。

The code is working fine in IE, but has a strange bug in Chrome and Safari. 该代码在IE中工作正常,但在Chrome和Safari中有一个奇怪的错误。 After the loading bar 'appears', it fails to load except when the element is selected in Chrome's developer tools 加载栏“出现”后, 除非在Chrome开发者工具中选择了该元素,否则加载失败

Find the HTML CSS and JS below. 在下面找到HTML CSS和JS。 Thanks in advance for any help given. 在此先感谢您提供的任何帮助。

<span id="loading-footer">
  <p class="loading-bar-text">Loading:</p>
  <div id="loading-bar"><div id="coloured-bar" style=""></div></div>
</span>

/*loading bar*/
#loading-footer { background-color: #444; height: 93px; margin-top: 27px; position:     absolute; width: 411px; display: none; border-radius: 4px; -moz-border-radius:4px; -webkit-border-radius:4px; }
#loading-footer .loading-bar-text { color: #CCCCCC; font-family: helvetica; font-weight: bold; margin: 10% 0 0 16%; width: 0; display: inline-block; }
#loading-footer #loading-bar { background-color: #151515; display: inline-block; height: 10px; margin: 0 0 -2px 75px; width: 201px; border:2px solid #394040; border-radius: 7px; -moz-border-radius:7px; -webkit-border-radius:7px; overflow: hidden; }
#coloured-bar { background: url('../images/loadingcolor.gif') left top; overflow: hidden; width: 1px; height: 10px; margin: 0 0 0 -5px; z-index: 200;}

window.onbeforeunload = function() {
  $("#loading-footer").stop().show('fast', function() {
    $("#coloured-bar").stop().animate({
      width: "250",
    },{queue:false,duration:5000});
  });
}

It works fine in Google Chrome when I do this: 当我这样做时,它在Google Chrome中可以正常工作:

$(document).ready(function() {
  $("#loading-footer").stop().show('fast', function() {
    $("#coloured-bar").stop().animate({
      width: "250",
    },{queue:false,duration:5000});
  });
})​

See it in action here . 看到它在这里行动。

You probably don't want to bind it to the $(document).ready event though but to the $(window).unload event, like this: 您可能不想将其绑定到$(document).ready事件,但希望将其绑定到$(window).unload事件,如下所示:

$(window).unload(function() {
  $("#loading-footer").stop().show('fast', function() {
    $("#coloured-bar").stop().animate({
      width: "250",
    },{queue:false,duration:5000});
  });
})​

Right... I have managed to centre onto the problem/bug, here is my description of it: 是的...我设法集中解决了问题/错误,这是我对它的描述:

As one may notice in the code above, I use a background image to represent the 'filler' in the loading bar. 就像上面的代码中可能注意到的那样,我使用背景图像来表示加载栏中的“填充物”。 When I replace this background image with a background colour, the loading works! 当我用背景色替换此背景图片时,加载工作正常!

I know the obvious argument... the link to the image was wrong; 我知道明显的论点……指向图像的链接是错误的; but it couldn't have been, as when the chrome developed tools were open the background image worked fine. 但事实并非如此,因为打开chrome开发的工具时,背景图片效果很好。 The background image also worked fine when the function to show() the loading bar was removed (leaving the animate as the only function) 删除show()加载条的功能时,背景图像也可以正常工作(将animate作为唯一功能)

Weird - [well maybe not, but I can't explain it] 很奇怪-[也许不是,但是我无法解释]

So to get around this problem I am going to use a colour instead of the background image... the difference is tiny anyway. 因此,要解决这个问题,我将使用一种颜色而不是背景图像...两者之间的差别仍然很小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AngularJs-仅在打开Chrome开发者工具时,$ watch才起作用 - AngularJs - $watch only works when Chrome Developer Tools is open Chrome开发者工具暂停了jQuery 1.7的初始化 - Chrome Developer Tools pauses the initialization of jQuery 1.7 在Chrome开发人员工具上测试jQuery / JS输出 - Testing jQuery/JS output on Chrome developer tools 谷歌Chrome开发者工具在控制台中与Jquery一起出现问题 - Google Chrome Developer Tools Issue with Jquery in the Console 打开chrome开发人员工具时的双重请求 - Double request when chrome developer tools open jQuery .animate()仅在Chrome中有效 - JQuery .animate() only works in Chrome Javascript 代码只能在 Chrome 开发者工具打开时在 Chrome 中工作 - Javascript code only works in Chrome while Chrome Developer Tools are open 在Chrome开发人员工具(或类似工具)中进行调试时,如何查找给定范围内的所有jQuery事件 - How to find all jQuery events within a given scope when debugging in Chrome Developer Tools (or similar) jQuery-在视口中出现时对数字进行动画处理 - jQuery - Animate numbers when appears in viewport 为什么 object.[[Prototype]] 在 Chrome 开发者工具中不起作用? - Why object.[[Prototype]] does not work in Chrome Developer Tools?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM