jQuery:卡住jQuery动画
对于wordpress主题,我将彩色图像转换为黑白图像。但是当你快速移动鼠标时,有时图像会一直保持黑白,直到你再次移动鼠标 我如何解决这个问题,以确保当我不悬停的图像,它不会停留在黑色和白色 链接到演示: 守则:jQuery:卡住jQuery动画,jquery,image,thumbnails,Jquery,Image,Thumbnails,对于wordpress主题,我将彩色图像转换为黑白图像。但是当你快速移动鼠标时,有时图像会一直保持黑白,直到你再次移动鼠标 我如何解决这个问题,以确保当我不悬停的图像,它不会停留在黑色和白色 链接到演示: 守则: function initImage(obj) { var $newthis = $(obj); if ($.browser.msie) { $newthis = $newthis.desaturateIm
function initImage(obj)
{
var $newthis = $(obj);
if ($.browser.msie)
{
$newthis = $newthis.desaturateImgFix();
}
$newthis.addClass("pair_" + ++paircount);
var $cloned = $newthis.clone().attr('id', '');
$cloned.get(0).onmouseover = null;
$cloned.insertAfter($newthis).addClass("color").hide();
$newthis = $newthis.desaturate();
$newthis.bind("mouseenter mouseleave", desevent);
$cloned.bind("mouseenter mouseleave", desevent);
};
function desevent(event)
{
var classString = new String($(this).attr('class'));
var pair = classString.match(/pair_\d+/);
// first I try was $("."+pair).toggle() but IE switching very strange...
$("."+pair).hide();
if (event.type == 'mouseenter')
$("."+pair).filter(":not(.color)").show();
if (event.type == 'mouseleave')
$("."+pair).filter(".color").show();
}
我以前也遇到过类似的问题,这是由于在jQuery处理以前的
show()
命令之前,鼠标引发了一个新的mouseenter/mouseleave事件造成的。解决此问题的最简单方法是添加一个通用命令,使所有彩色图像在运行过滤器以显示正在处理的彩色和黑白图像之前显示()
因此,基本上,将代码更改为:
function desevent(event) {
var classString = new String($(this).attr('class')),
pair = classString.match(/pair_\d+/);
$(".color").show();
$(":not(.color)").hide();
if (event.type == 'mouseenter')
$("." + pair).filter(".color").hide();
$("." + pair).filter(":not(.color)").show();
}
当mouseenter或mouseleave事件触发时,脚本将首先显示所有彩色图像并隐藏所有黑白图像。然后,如果是鼠标,脚本将隐藏彩色图像并显示黑白图像。这不是WordPress的问题。。。这是一个jQuery问题。请相应地改变你的头衔。哦,是的,对了,很抱歉