我有以下代码:
//new image on load
function theNewImg_onload(){
$bgimg.data("newImageW",this.width).data("newImageH",this.height);
BackgroundLoad($bgimg,this.width,this.height,this.src);
}
每当我更改网站上的图片背景时,javascript默认使用style =“display:none”更新CSS,有没有办法告诉JS设置display:block?
提前致谢。
编辑: BackgroundLoad是:
function BackgroundLoad($this,imageWidth,imageHeight,imgSrc){
$this.fadeOut("fast",function(){
$this.attr("src", "").attr("src", imgSrc); //change image source
FullScreenBackground($this,imageWidth,imageHeight); //scale background image
$preloader.fadeOut("fast",function(){$this.fadeIn("slow");});
var imageTitle=$img_title.data("imageTitle");
if(imageTitle){
$this.attr("alt", imageTitle).attr("title", imageTitle);
$img_title.fadeOut("fast",function(){
$img_title.html(imageTitle).fadeIn();
});
} else {
$img_title.fadeOut("fast",function(){
$img_title.html($this.attr("title")).fadeIn();
});
}
});
}
解决方法: 我发现我可以覆盖CSS上的默认值,标记为!important:
#bgimg {
width: 100%;
height: 100%;
position: fixed;
top: 0px;
left: 0px;
display: block !important;
z-index: 1;
}