javascript - 更改亮度滤镜

标签 javascript jquery html css

我尝试使用 jQuery 更改页面上某些图像的亮度过滤器 css 属性,但在控制台中收到以下错误:“解析“过滤器”值时出错。声明已删除。”

这是我正在使用的代码:

function changeBrightness() {
     $("#myImg").css({
     "filter"         : "brightness(50%)",
     "-webkit-filter" : "brightness(50%)",
     "-moz-filter"    : "brightness(50%)",
     "-o-filter"      : "brightness(50%)",
     "-ms-filter"     : "brightness(50%)"
     });
}

我还尝试了上述其他格式,只是为了看看它是否有效,但它们产生了相同的错误:

function changeBrightness() {
     var brightness = "brightness(50%)";
     $("#myImg")
        .css("filter",brightness)
        .css("webkitFilter",brightness)
        .css("mozFilter",brightness)
        .css("oFilter",brightness)
        .css("msFilter",brightness);
}

我也尝试了这种通用格式,希望 jQuery 能够处理前缀:

function changeBrightness() {
     $("#myImg").css("filter", "brightness(50%)");
}

当我单击按钮时,将调用changeBrightness函数,它应该将id为“myImg”的图像的亮度更改为50%。我使用的是 Firefox 24.7。 CSS3 的过滤器属性在 Firefox(或任何其他浏览器)中不起作用吗?

最佳答案

Is the filter property for CSS3 just not functional in firefox (or any other browsers)?

Here is the answer from MDN :

This is an experimental technology

Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the spec changes.

enter image description here

关于javascript - 更改亮度滤镜,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25043474/

相关文章:

JavaScript 验证无法正确执行

javascript - 缩短选择选项列表中的选定选项

javascript - 如何在window.write()里面写js

html - 为什么 Highcharts div/chart 会超出父 div?

javascript - 如何删除选择框中选项元素周围的蓝色边框和蓝色选项颜色

html - 在按钮之间添加空间?

javascript - CSS 技巧或 javascript

javascript - 新手问题: connect two functions int two files

javascript - 根据表格数据对表格行进行排序

javascript - location.replace() 并在返回数据时移动到新页面