CSS/HTML:点击删除图片过滤器 [英] CSS/HTML: Remove image filter on click

查看:120
本文介绍了CSS/HTML:点击删除图片过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一些图像用作网站上的链接.当我将鼠标悬停在其中一张图像上时,它们会从灰色变为彩色-当鼠标不再悬停时它们又变为灰色.

I use some images as links on my site. When I hover the mouse over one of the images, they go from gray to color - and they go back to gray when the mouse is no longer hovering.

我希望图像在激活后保持彩色.假设我点击了图片,那么在点击/激活另一个链接之前,图片应该保持彩色状态.

I want the image to stay colorized when activated. Say I click the image, it should stay colorized until another link is clicked/activated.

这是我的代码:

HTML:

<p><a href="privileged.php" target="testframe">
<img class="grayscale" height="67" src="powerlogo.png" width="303">
</a></p>
<iframe name="testframe"></iframe>

CSS:

img.grayscale {
  filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale"); /* Firefox 3.5+ */
  filter: gray; /* IE6-9 */
  -webkit-filter: grayscale(100%); /* Chrome 19+ & Safari 6+ */
}

a:hover img, a:focus img {
    filter: none;
    -webkit-filter: grayscale(0%);
}

以上功能可在Firefox中正常运行,但不能在Chrome和IE中运行.

The above works as intended in Firefox, but not in Chrome and IE.

我在做什么错了?

推荐答案

您可以在元素中添加/切换带有javascript的类,并使用CSS设置其样式:

You can add/toggle a class with javascript to your element and style this with css:

$("a").click(function(){
  $("a").removeClass("active");
  $(this).addClass("active");
});

a:hover img,
a:focus img,
a.active img {
  filter: none;
}

http://fiddle.jshell.net/3uYDc/

这篇关于CSS/HTML:点击删除图片过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆