简体   繁体   English

在图像的一部分中反转颜色 - HTML,CSS,JS

[英]inverting colors in part of an image - HTML, CSS, JS

Is there a way to invert only part of an image? 有没有办法只反转图像的一部分? I have a "selector bar" sort of thing, and I want the icon that's selected to be inverted. 我有一个“选择栏”的东西,我希望所选的图标被反转。 Unfortunately, this looks really bad when the bar is transitioning to a different selection, as the icon immediately changes color. 不幸的是,当条形图转换到不同的选择时,这看起来非常糟糕 ,因为图标会立即改变颜色。 The "selector" should slide along the bar while transitioning. 转换时,“选择器”应沿着条滑动。

Simple example of what I'm talking about can be found here 我在这里可以找到简单的例子

The best solution I can come up with right now is to put a new, inverted image on the selector element, and move the image the opposite direction the selector is moving. 我现在能想出的最佳解决方案是在选择器元素上放置一个新的反转图像,并将图像移动到选择器移动的相反方向。 That would give the illusion that the slice of the image that's covered is inverted. 这会产生一种错觉,即所覆盖的图像切片被反转。 Is that really the best way to do it? 这真的是最好的方法吗?

Create an element with zero width and height, and outline: 8px solid invert . 创建一个零宽度和高度的元素,并outline: 8px solid invert Then move this element around with your selector, and this will invert the stuff that it passes over. 然后用你的选择器移动这个元素,这将反转它传递的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM