[英]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.