我写了一个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?
您不能从'setTimeout'内的函数返回值。 –
我知道,但代码是使用CoffeeScript编写的。 CoffeeScript返回每个函数中的最后一条语句。但是,谢谢! :-) – Martin
你的代码有很多问题。首先,'setTimeout'只返回TimeoutHandle。其次,每个人都知道':hover'在网页浏览器中播放不好。而不是'return setTimeout(...);'把它写成'setTimeout(...); return $ this;' – Christian