Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更改javascript中的背景图像大小_Javascript_Html_Css - Fatal编程技术网

更改javascript中的背景图像大小

更改javascript中的背景图像大小,javascript,html,css,Javascript,Html,Css,我一直在尝试在一个网站上放一个重复的背景图片,使用基本的CSS background-image: url('url_here'); background-attachment: fixed; background-repeat: repeat; 但是,我希望能够使用javascript在刷新时更改im使用的图像的大小。CSS具有以下功能 background-size: 300px; 但不幸的是,COM样式的对象无法查看它对背景的作用。这给我留下了一个选择:使用一个重复自身的HTML图像,

我一直在尝试在一个网站上放一个重复的背景图片,使用基本的CSS

background-image: url('url_here');
background-attachment: fixed;
background-repeat: repeat;
但是,我希望能够使用javascript在刷新时更改im使用的图像的大小。CSS具有以下功能

background-size: 300px;
但不幸的是,COM样式的对象无法查看它对背景的作用。这给我留下了一个选择:使用一个重复自身的HTML图像,然后我可以用COM样式的对象进行编辑


所以,归结起来,我的问题是:有没有一种方法可以重复一个不是背景图像的HTML图像?非常感谢您的帮助。

实际上,您可以通过如下方式影响javascript中的背景大小:

document.getElementById("el_id").style.backgroundSize = "100px 100px";

看看这把小提琴:。CSS将背景图像大小设置为200px 200px,然后JS将其更新为100px X 100px。

这对我有效,我希望这对其他人有所帮助

var el = document.getElementById("notification");
el.style.background = 'url(images/Noti.png) no-repeat center center';
el.style.backgroundSize="100% 100%";
如果您觉得这很有用,请不要忘记投票:)

似乎使用:

style.backgroundSize = 300px;
代替:

style.background-size = 300px;
解决了这个问题,但我想指出一个速记版本:

style.background = "url('url_here') repeat fixed /300px";

请记住把背景尺寸放在最后,好像它在中间增加了一样。

你能添加更多的细节来说明为什么这有助于解决原来的问题吗?我不清楚它是否真的回答了这个问题。为了更好地回答这个问题,你可以重复引用。