views:

25

answers:

1

Mootools: How to get morpha.start() after 2sec mouseenter?

window.addEvent('domready',function() {
var morph = new Fx.Morph('resize',{duration:700,delay:400});
$$('#resize').addEvent('mouseenter',function(e){
    e.stop();
    morpha.start({
        width: '200px',
        height: '100px'
    });
}//It does not work on adding ',2000' here
);

<div id="resize" class="resize">DIV will get bigger after 2sec on mouseenter</div>

Thanks!

+1  A: 

use delay.

http://www.jsfiddle.net/dimitar/m6JKt/ example

document.id('resize').set("morph", {duration:700,delay:400}).addEvents({
    mouseenter: function(){
        this.store("timer", (function() {
            this.morph({
                width: '200px',
                height: '100px'
            });
        }).delay(2000, this));
    },
    mouseleave: function() {
        $clear(this.retrieve("timer"));
    }
});

this has also been refactored to use element.morph which does the class instance for you - and it will cancel the transition if you mouseout within the 2 seconds starting period grace.

Dimitar Christoff
@Dimitar Christoff: Thanks! I add `timer` also for `mouseleave` http://www.jsfiddle.net/hnmJa/. Is it fine done?
Binyamin
adding it is fine but where do you cancel it?
Dimitar Christoff
@Dimitar Christoff: Do I really need to do it? So it does not work - http://www.jsfiddle.net/hnmJa/1/
Binyamin