JQuery mousemove () is activated without mouse movement

I try to make google.com as fade in (Cept, I want the text to fade)

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
  $(document).ready(function() {
    $("html").mousemove(function () {
      $("p").fadeOut("slow");
    });
  });
</script>

With this code, my extinction is automatically activated, although I did not move the mouse. It happens in all browsers. Any tips?

+3
source share
3 answers

Since the event fires once, and mousemovefires every time you move it by a pixel, you can simply ignore the very first (possibly automatic, depending on the browser) event mousemoveto get the desired effect, for example

$(function() {
  var moveCount = 0;
  $("html").mousemove(function () {
    if(moveCount++ === 0) return; //first run?
    $("p").fadeOut("slow");
    $(this).unbind('mousemove'); //unbind this, no need to stick around
  });
});​

, , , mousemove, , mousemove , .

+5

, , . , - , F5 , . F5 . , , . , , Escape , . , , .

Chrome 5 Windows 7. , , , .

+1

Are you sure there are no "micro-movements"? Sometimes an optical mouse can cause movements to be recorded only with dust or dirt.

0
source

Source: https://habr.com/ru/post/1752008/


All Articles