How to check that a mouse holds a second or a millisecond on a marker using google event listener?

Using the Google map mouseover event Listener to call a function, as shown below. I only need the exicute function if the user held the mouse for more than a second on the creator.

google.maps.event.addListener(marker, 'mouseover', function() {

        OnMouseoverMarker(marker);

    });

code>

Any quick fix?

0
source share
1 answer

Use setTimeoutto call the desired function with a delay.
To turn off the output timeout, use clearTimeout.

Example:

         google.maps.event.addListener(marker, 'mouseover', function(){
            var that=this;
            clearTimeout(this.timer)
            this.timer=setTimeout(function(){OnMouseoverMarker(that);},1000)
            google.maps.event.addListenerOnce(this,'mouseout',
                                              function(){clearTimeout(this.timer);});
         });
+2
source

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


All Articles