سؤال

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);
هل كانت مفيدة؟

المحلول

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);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top