jQuery mouseleave IE无法正常工作

时间:2012-03-02 23:06:02

标签: javascript jquery html internet-explorer mouseleave

所以这是我的剧本:

$(document).bind('mouseleave', function(event) {        
            // show popup
            console.log("you are about to leave the form!");
            //Get the A tag
            var id = $("#dialog");

            //Get the screen height and width
            var maskHeight = $(document).height();
            var maskWidth = $(window).width();

            //Set heigth and width to mask to fill up the whole screen
            $('#mask').css({'width':maskWidth,'height':maskHeight});

            //transition effect     
            $('#mask').fadeIn(250); 
            $('#mask').fadeTo("slow",0.8);  

            //Get the window height and width
            var winH = $(window).height();
            var winW = $(window).width();

            //Set the popup window to center
            $(id).css('top',  winH/2-$(id).height()/2);
            $(id).css('left', winW/2-$(id).width()/2);

            //transition effect
            $(id).fadeIn(500);
    });

此代码适用于所有浏览器但IE浏览器。它似乎工作的唯一时间是我激活了“开发人员工具”......实际可绑定的“mouseleave”触发器似乎不起作用。

有什么想法吗?


似乎IE不喜欢该方法中的“console.log”调用。一旦我删除了该引用,一切正常。

有人可以告诉我为什么会这样吗?

1 个答案:

答案 0 :(得分:0)

当开发者工具开启时,IE仅支持console.log()。我认为这只是他们做出的一项设计决定。您可以通过定义自己的日志记录功能来尝试在代码中克服这个问题:

var log = function(s) {
  try {
    console.log(s);
  } catch (e) {
    alert(s); // If you want to see annoying popups.
  }           // If not, just leave this empty.
}