Function Mouse Screen

Asked

Viewed 155 times

-2

That function that captures mouse movement does not work , what is wrong in it how to fix ?

    <script>
        $(document).bind("mouseleave", function(e) {
            if (e.pageY - $(window).scrollTop() <= 1) {
                alert('Tem certeza que quer fechar a aba? :(');
            }
        });
    </script>

1 answer

0


It’s as close as you can get

$(document).mousemove(function(e) {
    // $("body").html("posição do mouse: " + (e.pageY - $(window).scrollTop()))
    if ((e.pageY - $(window).scrollTop()) == 0){
      alert('Tem certeza que quer fechar a aba? :(');
    }
});

// Ou

$(window).mouseleave(function() {
   alert('Tem certeza que quer fechar a aba? :(');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

  • Thank you, Wéllingthon M. de Souza !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.