html背景图灰度,灰度背景的CSS图片(Greyscale Background Css Images)

这篇博客介绍了如何使用CSS实现背景图像的灰度渐变效果,并在Firefox、Chrome和IE浏览器中进行了测试。作者提供了一段jQuery代码,实现了鼠标悬停时背景图像在灰度和原始颜色间切换的交互功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

干得好:

bluantinoo CSS Grayscale Bg Image Sample

div {

border: 1px solid black;

padding: 5px;

margin: 5px;

width: 600px;

height: 600px;

float: left;

color: white;

}

.grayscale {

background: url(yourimagehere.jpg);

-moz-filter: url("data:image/svg+xml;utf8,#grayscale");

-o-filter: url("data:image/svg+xml;utf8,#grayscale");

-webkit-filter: grayscale(100%);

filter: gray;

filter: url("data:image/svg+xml;utf8,#grayscale");

}

.nongrayscale {

background: url(yourimagehere.jpg);

}

this is a non-grayscale of the bg image

this is a grayscale of the bg image

在Firefox,Chrome和IE浏览器进行了测试。 我还附有图片,以显示我的我实现这个结果。

6c1555302777729326ca3efa0910d9ec.png

编辑:另外,如果你想要的形象只是来回切换使用jQuery,下面是该页面的源代码...我已经列入本网站链接的jQuery和和形象,不在线,所以你就应该能够复制/粘贴到测试一下:

bluantinoo CSS Grayscale Bg Image Sample

div {

border: 1px solid black;

padding: 5px;

margin: 5px;

width: 600px;

height: 600px;

float: left;

color: white;

}

.grayscale {

background: url(http://www.polyrootstattoo.com/images/Artists/Buda/40.jpg);

-moz-filter: url("data:image/svg+xml;utf8,#grayscale");

-o-filter: url("data:image/svg+xml;utf8,#grayscale");

-webkit-filter: grayscale(100%);

filter: gray;

filter: url("data:image/svg+xml;utf8,#grayscale");

}

.nongrayscale {

background: url(http://www.polyrootstattoo.com/images/Artists/Buda/40.jpg);

}

$(document).ready(function () {

$("#image").mouseover(function () {

$(".nongrayscale").removeClass().fadeTo(400,0.8).addClass("grayscale").fadeTo(400, 1);

});

$("#image").mouseout(function () {

$(".grayscale").removeClass().fadeTo(400, 0.8).addClass("nongrayscale").fadeTo(400, 1);

});

});

rollover this image to toggle grayscale

编辑2(对于IE10-11用户):上述解决方案将不会与微软浏览器作出的后期变化工作,所以这里是一个更新的解决方案,让您为灰度(或饱和度)图像。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值