我想将背景图片的大小调整为原始大小的30%,然后将其用作元素的背景。我确信我的错误在最后一行的某个地方。 这是我的代码:
var img = new Image();
img.src = "wallpaper.jpg";
var a = img.height;
var newWidth = (img.width*0.3));
var newHeight = (img.height*0.3));
t.getBody().style.backgroundImage = "url("+img.src+")";
t.getBody().style.backgroundSize = "(newWidth)px (newHeight)px";
答案 0 :(得分:1)
background-size
属性的值应与Xpx Ypx
类似。尝试更改您的最后一行:
t.getBody().style.backgroundSize = newWidth+"px "+newHeight+"px";
答案 1 :(得分:1)
用newWidth和newHeight值替换它们之间的空格。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><div id="res">Some text inside DIV
<img alt="Class-A warehouse facility developed by Panattoni Europe in Germany for Rudolph Logistik Gruppe." src="http://europe-re.com/wp-content/uploads/2012/12/Gruppe.jpg"></div></body></html>