Firefox不能正确处理jQuery $(window).load [英] Firefox does not handle jQuery $(window).load properly
本文介绍了Firefox不能正确处理jQuery $(window).load的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个div#所有与背景,我想它淡入onLoad。 Chrome和IE尊重window.load,而Firefox不支持。 Firefox等待fadeIns(1500 + 500)中的时间,然后显示没有任何效果的内容
Having a div#all with background, I want it to fade in onLoad. Chrome and IE honors the window.load, whereas Firefox does not. Firefox waits the amount of time in fadeIns (1500+500) and then displays the contents without any effect
CSS
body {
display: none;
}
#all{
background: url('../bg.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
HTML
<body>
<div id="all">
All contents here
<div id="home" style="display:none">Content</div>
</div>
</body>
jQuery
$(window).load(function() {
$("body").fadeIn(1500,function(){
$('#home').fadeIn(500);
});
});
推荐答案
看来文字正确淡出,
Taking a cue from "How can I check if a background image is loaded?"
$(window).load(function() {
$('<img/>').attr('src', '../bg.jpg').load(function() {
$(this).remove();
$("body").fadeIn(1500,function(){
$('#home').fadeIn(500);
});
});
});
这样,它首先等待背景图像加载,然后开始淡入。
This way it first waits for the background image to load before starting the fade-in.
(如果没有镜像加载检查,它在Chrome上无法正常工作。)
(NB Without the image-load check it didn't work well on Chrome for me either.)
这篇关于Firefox不能正确处理jQuery $(window).load的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文