我写了一个 jQuery 插件,它使元素产生脉冲。它在 Chrome 和 Internet Explorer 9 中运行良好。在 Internet Explorer 8 中,它在调用 setTimeout 后不起作用。
我创建了一个 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?
最佳答案
jQuery 不再有 :hover
选择器。一些浏览器原生支持 :hover
,但其他浏览器不支持。 jQuery 曾经使用它的 CSS 引擎 Sizzle 来解决这个问题,但现在不再使用了。
尝试使用hover
(或mouseenter
/mouseleave
)事件。
关于javascript - jQuery 插件 : ":hover" doesnt work in IE8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13038381/