0

我有以下代码:

//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 上的默认值,将其标记为!重要:

#bgimg {
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0px;
    left: 0px;
    display: block !important;
    z-index: 1;
}
4

0 回答 0