鼠标悬停更改图像颜色
我有一个很大的图像网格。当用户将鼠标悬停在图像上时,我希望图像呈蓝色 0000FF。有没有办法在 JS 或 jquery 中做到这一点?理想情况下,我不必对每个图像应用一个类。这种处理应该会影响屏幕上的所有图像。
在搜索此处和其他地方的论坛后,我了解到有些人在具有颜色和不透明度的图像上使用 div,但我如何将其应用于所有 img?
我一直看到的另一件事是 PaintbrushJS 和 pixastic,但我不知道如何使它们用于此目的。
这是我正在处理的页面: http://www.rollinleonard.com/elements/
编辑:图像需要可点击,这样 div 就不会遮挡链接的 img。有没有办法点击div或将div放在下面什么的?提供的一些解决方案不使用 div,但我无法弄清楚它们。
谢谢! 罗林
I have a big grid of images. When a user mouseovers an image I want the image to tint blue 0000FF. Is there a way to do this in JS or jquery? Ideally, I wouldn't have to apply a class to each image. This treatment should affect all images on the screen.
After searching the forums here and elsewhere I learned that some folks use a div over the image that has a color and opacity, but how would I apply that to all img?
Another thing I keep seeing is paintbrushJS and pixastic but I don't know how to make those work for this purpose.
Here's the page I'm working on:
http://www.rollinleonard.com/elements/
EDIT: the images need to be be clickable so the div can't obstruct the linked img. Is there a way to click through the div or put the div below or something? Some solutions offered don't use a div but I can't figure them out.
Thanks!
Rollin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这就是你想要的方式:http://jsfiddle.net/ztKJB/1/
Javascript / jQuery:
CSS:
HTML:
This is how you're gonna want to do it: http://jsfiddle.net/ztKJB/1/
Javascript / jQuery:
CSS:
HTML:
在图像上使用 div 的想法是可行的。您可以根据需要即时生成 div(或生成隐藏的 div 以在整个页面中重复使用),并在 onmouseover 事件期间将其放置在图像上:
The idea of using a div over the image would work. You can generate the div on-the-fly as needed (or generate a hidden div to reuse throughout the page), and position it over the image during the onmouseover event:
在每个锚点内附加一个
span
,并在悬停时调整其不透明度:注意:您需要调整样式,以便锚点
浮动
而不是图像。如果您想要淡入/淡出,可以使用 CSS3 过渡 或隐藏最初使用
span
并使用 jQuery mouseover 事件将其淡入:Append a
span
inside each anchor, and adjust it's opacity on hover:Note: you'll need to adjust your styles so the anchors are being
float
ed rather than the images.If you wanted a fade in/out, you could either use CSS3 transitions or hide the
span
initially and use a jQuery mouseover event to fade it in:这个 jquery 插件应该很好地完成你要求的事情。 (tancolor.js)
有一个交互式演示。你可以玩玩它。
查看使用文档,非常简单。 文档
This jquery plugin should do the thing you asked pretty well. (tancolor.js)
There's an interactive demo. You can play around with it.
Check out the documentation on the usage, it is pretty simple. docs