Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An "if mouseover" or a "do while mouseover" in JavaScript/jQuery

Is there a JavaScript or jQuery solution to run a function repeatedly (after setTimeout) while the mouse is over a DOM object? Otherwise said, is there a JavaScript "do while mouseover" (or "if mouseover")?

    $('someObject').bind('mouseover', function() {

        //Do the following while mouseover 
        $('someOtherObject').css('margin-left',adjustedLeft + 'px');
        setTimeout(/*do it again*/,25);

    });
like image 880
Kyle Cureau Avatar asked Oct 19 '10 07:10

Kyle Cureau


People also ask

What is the difference between hover and mouseover events in jQuery?

The hover()method binds handlers for both mouseenter and mouseleave events. Basically, with the hover() method, we will specify what to do when the cursor enters the element and we will specify what to do when the cursor leaves that element. Parameters: It accepts two functions i.e. handlerIn and handlerOut.

What is the difference between Mouseenter () and mouseover () event?

The mouseover event triggers when the mouse pointer enters the div element, and its child elements. The mouseenter event is only triggered when the mouse pointer enters the div element. The onmousemove event triggers every time the mouse pointer is moved over the div element.

What is the mouseover function jQuery?

The mouseover() method is an inbuilt method in jQuery which works when mouse pointer moves over the selected elements. Parameters: This method accepts single parameter function which is optional. This parameter is used to specify the function to run when the mouseover event is called.

What does mouseover do in Javascript?

The mouseover event is fired at an Element when a pointing device (such as a mouse or trackpad) is used to move the cursor onto the element or one of its child elements.


1 Answers

$('someObject').on('mouseenter', function() {
    this.iid = setInterval(function() {
       // do something           
    }, 25);
}).on('mouseleave', function(){
    this.iid && clearInterval(this.iid);
});

Example Look here

like image 141
jAndy Avatar answered Oct 04 '22 23:10

jAndy