gnomeontherun
11-28-2008, 06:59 PM
I have an image which I want to move around slightly, like a boat on water, when the cursor is over. I have used Effect.Move to create this with an effect queue. Here is the code.
Javascript
function FloatIt(element){
new Effect.Move(element, { x: 10, y: -10, mode: 'relative', duration: 2.2, queue: { position: 'end', scope: 'fscope' } });
new Effect.Move(element, { x: -20, y: 5, mode: 'relative', duration: 2.2, queue: { position: 'end', scope: 'fscope' } });
new Effect.Move(element, { x: 5, y: -15, mode: 'relative', duration: 2.2, queue: { position: 'end', scope: 'fscope' } });
new Effect.Move(element, { x: -5, y: 20, mode: 'relative', duration: 2.2, queue: { position: 'end', scope: 'fscope' } });
}
function StopFloatIt(element){
var queue = Effect.Queues.get('fscope');
queue.each(function(effect) { effect.cancel(); });
}
HTML
<span id="floater"><a href="#" onmouseover="FloatIt('floater');" onmouseout="StopFloatIt('portfolio');">Float me!</a></span>
My questions are these:
1) I have only been able to Stop the floating where it is, so when I mouseout, it does not return to its original location. Can I somehow save the original location and have it float back there?
2) Is there another way so that only the span floats, and the link itself stays? I tried moving it outside of the span, but then it did not function when rolling over the link. PS, the span is a block element in the CSS, and I want the link to activate the floating, not the image itself.
3) Is there any other way to simulate this effect? I know other frameworks are out there, but I'll take suggestions or ideas?
Thanks!
Javascript
function FloatIt(element){
new Effect.Move(element, { x: 10, y: -10, mode: 'relative', duration: 2.2, queue: { position: 'end', scope: 'fscope' } });
new Effect.Move(element, { x: -20, y: 5, mode: 'relative', duration: 2.2, queue: { position: 'end', scope: 'fscope' } });
new Effect.Move(element, { x: 5, y: -15, mode: 'relative', duration: 2.2, queue: { position: 'end', scope: 'fscope' } });
new Effect.Move(element, { x: -5, y: 20, mode: 'relative', duration: 2.2, queue: { position: 'end', scope: 'fscope' } });
}
function StopFloatIt(element){
var queue = Effect.Queues.get('fscope');
queue.each(function(effect) { effect.cancel(); });
}
HTML
<span id="floater"><a href="#" onmouseover="FloatIt('floater');" onmouseout="StopFloatIt('portfolio');">Float me!</a></span>
My questions are these:
1) I have only been able to Stop the floating where it is, so when I mouseout, it does not return to its original location. Can I somehow save the original location and have it float back there?
2) Is there another way so that only the span floats, and the link itself stays? I tried moving it outside of the span, but then it did not function when rolling over the link. PS, the span is a block element in the CSS, and I want the link to activate the floating, not the image itself.
3) Is there any other way to simulate this effect? I know other frameworks are out there, but I'll take suggestions or ideas?
Thanks!