2012-10-23 74 views
1

我写了一个jQuery插件,使元素脉冲。它在Chrome和Internet Explorer 9中运行良好。在Internet Explorer 8中,在setTimeout调用后它不工作。jQuery插件:“:悬停”不工作在IE8

我创建了一个的jsfiddle来演示该问题:http://jsfiddle.net/Guykp/ 这里的javascript代码:

$(document).ready(function() { 
    $.fn.pulseEffect = function(delay, duration) { 
    var $element, animateOptions; 
    $element = $(this); 
    if (!$element.is(":hover")) { 
     animateOptions = { 
     opacity: $element.css("opacity") === "1" ? .6 : 1 
     }; 
     $element.animate(animateOptions, duration); 
    } 
    return setTimeout((function() { 
     return $element.pulseEffect(delay, duration); 
    }), delay + duration); 
    }; 

    $("#pulse-element").pulseEffect(0, 1000); 
}); 

我怎样才能使它在Internet Explorer 8的工作?

这是从Internet Explorer 8的错误消息:语法错误,不能识别的表达式:不支持的伪:悬停

这是解决方案: How do I check if the mouse is over an element in jQuery?

+0

您不能从'setTimeout'内的函数返回值。 –

+1

我知道,但代码是使用CoffeeScript编写的。 CoffeeScript返回每个函数中的最后一条语句。但是,谢谢! :-) – Martin

+2

你的代码有很多问题。首先,'setTimeout'只返回TimeoutHandle。其次,每个人都知道':hover'在网页浏览器中播放不好。而不是'return setTimeout(...);'把它写成'setTimeout(...); return $ this;' – Christian

回答

2

jQuery没有:hover选择器了。某些浏览器本地支持:hover,但其他浏览器则不支持。 jQuery过去使用它的CSS引擎Sizzle来实现这一点,但它不再这样做。

尝试使用hover(或mouseenter/mouseleave)事件。

0

其像

$('li:hover).css('display', 'block');相当于$().css('display', 'block');

像火箭Hazmat说使用jquery hover