Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.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_Css - Fatal编程技术网

如何使用javascript更改背景图像的透明度?

如何使用javascript更改背景图像的透明度?,javascript,css,Javascript,Css,我有一个元素的重复不透明背景。我需要能够使用javascript更改背景图像的不透明度。我想根据滚动位置调整图像不透明度 我发现这个链接是使用css“after”伪类实现的: 但看起来我无法使用javascript更改伪类的属性。 有人知道我是如何做到这一点的吗?试试这样的方法: HTML: JavaScript: document.getElementById("img").style.opacity=0.5; #img{background:url(enter your image fil

我有一个元素的重复不透明背景。我需要能够使用javascript更改背景图像的不透明度。我想根据滚动位置调整图像不透明度

我发现这个链接是使用css“after”伪类实现的:

但看起来我无法使用javascript更改伪类的属性。
有人知道我是如何做到这一点的吗?

试试这样的方法:
HTML:

JavaScript:

document.getElementById("img").style.opacity=0.5;
#img{background:url(enter your image file url here); width:100%; height:100%;}
document.getElementById("img").style.opacity=0.5;