简体   繁体   English

使用Javascript扩展响应式HTML的背景图片

[英]Responsive HTML's background image stretching with Javascript

I got stuck for hours in this code, trying to modify HTML's background so that it can be automatically resized as the browser's resized by user, i'm trying to modify that through javascript : (i'm in firefox btw) 我在这段代码中停留了几个小时,试图修改HTML的背景,以便可以根据用户调整浏览器的大小自动调整它的大小,我正在尝试通过javascript进行修改:(我在firefox btw中)

GM_addStyle('body {background-image: url("chrome://browserbackgrounds/content/browserbackgrounds
/Generic/Backgrounds/wall.jpg")}');

var images = document.getElementsByTagName ("img");
var x=0;
while(x<images.length)
{
if(images[x].src == "https://www.google.com/images/nav_logo170.png")
{
images[x].src = "chrome://browserbackgrounds/content/browserbackgrounds/Generic/Backgrounds   
/wall.jpg";
}
x=x+1;
}

now below is the part where i got stucked 现在下面是我卡住的部分

document.getElementById("gsr").style.MozBackgroundSize="Cover";
document.getElementById("gsr").style.WebkitBackgroundSize="Cover";
document.getElementById("gsr").style.OBackgroundSize="Cover";
document.getElementById("gsr").style.BackgroundSize="Cover";

Did you try with backgroundSize ? 您尝试使用backgroundSize吗? (notice the lowercase initial b ). (注意小写的首字母b )。 Same for the rest of properties, they need to be camelCased . 其他属性也一样,它们需要camelCased

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM