redcoder
redcoder

Reputation: 1

mootool event delay on specifed timing

anyone come across a code that only fire event when the mouse enter the element for certain time ? but won't fire event if only hover or passed thru the element quickly..

Upvotes: 0

Views: 114

Answers (2)

Oskar Krawczyk
Oskar Krawczyk

Reputation: 3502

Using setTimeout, it's not the MooTools way. What you should use is the framework's methods:

var theDiv = $$('div')[0];
var foo = function(){
    theDiv.highlight();
};
var timer;

theDiv.addEvents({
    mouseenter: function() {
        timer = foo.delay(1000);
    },

    mouseleave: function() {
        $clear(timer);
    }
});​

See a working example: http://www.jsfiddle.net/oskar/SZsNT/

Upvotes: 1

fantactuka
fantactuka

Reputation: 3334

var timer = null;
element.addEvents({
  mouseenter: function() {
    timer = setTimeout(foo, 5000);
  },

  mouseleave: function() {
    clearTimeout(timer);
  }

});

So foo will be called only if cursor was over element for 5 seconds

Upvotes: 0

Related Questions