views:

18

answers:

1

So, the highlight element method is great!

$('flashyflashy').highlight('#fcc');

Except it's in an out much too quickly - are there any options I can modify, similar to Tween's duration: 'long'?

Thanks :)

+1  A: 

You could modify the default tween duration on the elements in question. For example, if you want the tween on the element with the id 'flashyflashy' to have a duration of 2000ms instead of the default 500ms, call the following:

$("flashylflashy").get("tween").options.duration = 2000;

That should slow down the elements default tween instance, and thus slow down the highlight method.

You could also implement a custom highlight function:

Element.implement({
    highlight: function(start, end, duration){
        if (!end){
            end = this.retrieve('highlight:original', this.getStyle('background-color'));
            end = (end == 'transparent') ? '#fff' : end;
        }
        var tween = this.get('tween');
        tween.options.duration = duration;
        tween.start('background-color', start || '#ffff88', end).chain(function(){
            this.setStyle('background-color', this.retrieve('highlight:original'));
            tween.callChain();
        }.bind(this));
        return this;
    }
});

That should allow you to pass through not only the start/end colors, but also the duration that the highlight should use. Above code untested, but it should work fine.

Seidr
Cheers! I never thought about slowing the whole Tween class down for that element... makes sense.
Julian H. Lam
You're welcome.I agree, it's a bit of a brute-force solution, as highlight is not the only function to use the elements tween instance and as such is not the most ideal solution - but it works.. ;)
Seidr
Be warned that doing `el.get("tween").options.duration = 2000;` will not work from MooTools 1.2.5 since doing a `el.get()` to **set** something was a bug, now it'll work as it should `el.set('tween', {duration: 2000})`.
Oskar Krawczyk
Good point - I haven't implemented it yet, but thanks for the heads up.
Julian H. Lam
Thanks Oskar - I missed the patch notes for 1.2.5.
Seidr
always thought it was counter intuitive what some people did with the getter here (and in other instances). although it makes sense that the get here retrieves the fx.tween instance, it's still wrong imo :)
Dimitar Christoff