javascript - 有没有办法使用 jQuery 和/或 CSS 通过单击按钮来反转页面上的所有颜色?

标签 javascript jquery html css colors

我希望通过单击按钮反转页面上的所有颜色,但我还没有学会反转颜色。有没有办法用 jQuery 或 JS 方法来实现这一点,例如:

$("#button").click(function() {
  $(body).invert()
}

或者我必须通过CSS方法吗?

谢谢。

最佳答案

是的,您可以使用 CSS 来做到这一点:

body.invert {
  filter: invert(1);
}

https://developer.mozilla.org/en-US/docs/Web/CSS/filter-function/invert

只需通过 JS 单击切换类 .invert 即可。

关于javascript - 有没有办法使用 jQuery 和/或 CSS 通过单击按钮来反转页面上的所有颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59782883/

相关文章:

javascript - 这个小鸟动画是怎么画的?

javascript - 使用 appendChild 将图像添加到元素会产生错误

javascript - 使用jQuery检测用户何时滚动到div的底部

JQuery 对象与 HTMLElementxxx 对象

javascript - jquery 在页面中间居中一个div

python - 我有 4 个嵌套的 div 标签,当我使用 find_all 打印文本时,它打印文本 4 次

javascript - Redux - 商店不起作用

JavaScript 图像牌组通过 z-index 随机播放

javascript - 将 Accordion 滑动到浏览器顶部

javascript - Angular 2 : Setting and maintaining a CSS class when clicking on an element