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