jQuery插件:“:hover”在IE8中不起作用

时间:2012-10-23 20:07:33

标签: javascript jquery

我已经编写了一个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的错误消息:语法错误,无法识别的表达式:unsupported pseudo:hover

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

2 个答案:

答案 0 :(得分:2)

jQuery不再有:hover选择器了。有些浏览器本身支持:hover,但其他浏览器则不支持。 jQuery过去常常使用它的CSS引擎Sizzle,但它不再使用它。

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

答案 1 :(得分:0)

喜欢

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

像Rocket Hazmat所说的那样使用jquery hover