Question

I have a tween effect that works fine with a click event but I would like it to work with periodical. Please help! Thanks in advance.

// Tween effect
var bounce = function() {
    this.set('tween', {duration: 1500, transition: 'bounce:out'});
    this.tween('right', [900, 40]);
}

// This works fine
$('someID').addEvent('click', bounce);

// These don't work
bounce();
bounce.periodical(10000);
Était-ce utile?

La solution

When you attach the bounce() to the click event then you can use this in that function, but outside that you need to define the "this". You could use bind, or change this to your element.

Try this:

var bounce = function() {
    var element = $('someID'); // cache it here or outside the function
    element.set('tween', {duration: 1500, transition: 'bounce:out'});
    element.tween('right', [900, 40]);
}

bounce();
bounce.periodical(10000);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top