【发布时间】:2013-05-04 05:53:15
【问题描述】:
我正在尝试在完成加载时显示具有fadein() 效果的 div 背景。
我一直在搜索,离我越近的是this topic(在<img> 标签上效果很好)。
我想对 div 的 css 背景属性做同样的事情。这是我正在尝试工作的代码:
HTML
<div id="some_target"></div>
CSS
#some_target {
position: absolute;
width: 100%; height: 100% ;
}
jQuery
$(document).ready(function() {
var newImage = "url(http://vanusasousa.com.br/sicom/img/background2.jpg)"; //Image name
$("#some_target").hide() //Hide it
.one('load', function() { //Set something to run when it finishes loading
$(this).fadeIn(); //Fade it in when loaded
})
.css('background', newImage) //Set the background image
.each(function() {
//Cache fix for browsers that don't trigger .load()
if(this.complete) $(this).trigger('load');
});
});
对我来说它看起来不错,但它不起作用。 Here is the jsFiddle我在工作。
有谁知道我做错了什么?
谢谢大家。
【问题讨论】:
标签: jquery css background fadein