在css/javascript中单击,切换图像上的去饱和度
Toggle Desaturation on image onClick in css / javascript
每个函数都有更多的代码,但我相信这些是与我的问题有关的主线。。。这是从一个家伙库去饱和的图像基本上滚动。
如何将其更改为单击,而不是鼠标悬停/滚动?这是他的密码。。。
jQuery(function($){
$cloned.closest(".DesaturateDiv").bind("mouseenter mouseleave",desevent);
}
function desevent(event)
{
if (event.type == 'mouseenter')
$(".des.color", this).fadeOut(275);
if (event.type == 'mouseleave')
$(".des.color", this).fadeIn(200);
}
我已经尝试过将if语句更改为jquery切换,并将最上面的一行从.bind("mouseenter-moseleave",desevent)更改为。。。到.bind("toggle",desevent),它仍然不起作用。我的问题基本上是如何将mouseenter和mouseleave替换为onClick,这样图像在onClick上会去饱和,然后在onClicks上再次饱和。这是我输入的切换代码,而不是上面的两个if,只是以防万一。
$('.DesaturateDiv').toggle(function() {
$(".des.color", this).fadeOut(275);
}, function() {
$(".des.color", this).fadeIn(200);
});
此外,在一个相关的问题上,你能用css3做到这一点吗?这是用css3…去饱和图像的代码
img.desaturate{
filter: grayscale(100%);
-webkit-filter: grayscale(100%); -moz-filter: grayscale(100%);
-ms-filter: grayscale(100%); -o-filter: grayscale(100%);
filter: url(desaturate.svg#greyscale);
filter: gray;
-webkit-filter: grayscale(1);
}
所以我的问题是如何做到这一点?
我尝试了img。desaturate:active{},但它不起作用?
编辑:我试过了,觉得我需要一些类似的东西,但我确信语法不正确,有帮助吗??
function desevent(event)
{
i = 0;
if( i = 0 ){
if (event.type == 'mousedown')
$(".des.color", this).fadeOut(275);
i = 1;
}
if( i = 1 ){
if (event.type == 'mousedown')
$(".des.color", this).fadeIn(200);
i = 0;
}
}
只需向单击的元素添加一个特定的类。
.desaturate{
transition-duration: 400ms; //and other prefixes
}
.desaturate.active{
filter: grayscale(100%);
-webkit-filter: grayscale(100%); -moz-filter: grayscale(100%);
-ms-filter: grayscale(100%); -o-filter: grayscale(100%);
filter: url(desaturate.svg#greyscale);
filter: gray;
-webkit-filter: grayscale(1);
}
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- nodejs-expressjs上传图像并显示它们
- 使用JSP从服务器检索和显示图像
- 角度:在ng重复上切换图像
- 画廊图像未显示
- Phonegap-(安卓/iphone)多个图像的图像库出现问题
- Javascript排序的图像弹出窗口..可以't单独弹出
- 画布数据到图像
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- 使图像在单击时展开到不大于浏览器
- Html页面上的多个Base64图像和平滑加载
- UIAutomation放大图像
- 使用javascript在Flash中加载外部图像
- 可以在这里为背景图像设置滤镜吗
- 当图像转换为本地存储的DataURL时,EXIF被删除
- 使用 js 将背景图像设置为 HTML
- Javascript将图像src更改为淡入淡出
- 在css/javascript中单击,切换图像上的去饱和度
- 静态贴图API添加色调|饱和度|亮度会破坏图像
- 我如何在HTML5 Canvas中调整图像的房屋,饱和度和亮度