javascript 通过javascript动态设置css过滤器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14802986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 22:37:47  来源:igfitidea点击:

Dynamically set css filters via javascript

javascriptcss

提问by seanlevan

I'd like to apply this filter:

我想应用这个过滤器:

-webkit-filter: blur();

dynamically via JavaScript.

动态地通过 JavaScript。

I looked everywhere online, and I couldn't find almost anything.

我在网上到处找,几乎找不到任何东西。

I would like to set the property dynamically through JavaScript via the DOM.

我想通过 DOM 通过 JavaScript 动态设置属性。

document.getElementById("element").style

How would I go about this?

我该怎么办?

回答by VisioN

As simple as:

就这么简单:

document.getElementById("element").style.webkitFilter = "blur(1px)";