jQuery mouseleave IE не работает - PullRequest
0 голосов
/ 03 марта 2012

Итак, вот мой сценарий:

$(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 голосов
/ 03 марта 2012

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.
}
...