문제

For example, doing this:

new Effect.Move('agrupador', { x: -100, y: 0, mode: 'relative' });
Element.setStyle('agrupador', {left: '0px' });

The left position is applied before the element moves left, but I want the opposite.

Is there any way of doing this?

PD: I will burn prototype, I promise.

도움이 되었습니까?

해결책

Here's a fiddle:

http://jsfiddle.net/uF9Dh/

new Effect.Move('agrupador', {
    x: -100,
    y: 0,
    mode: 'relative',
    afterFinish: function() {
        Element.setStyle('agrupador', {left: '0px' });
    }
});
​

The move effect is asynchronous. When you call new Effect.Move(), you're setting up something to happen over the course of one second. In the code you posted, you set the left property to 0px after you instantiated the effect, not after the effect has finished. There's an afterFinish callback for this purpose. You can check out the other available callbacks for Scriptaculous effects here.

BTW - This issue was not Prototype or Scriptaculous specific, but rather the way asynchronous actions in Javascript work.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top