jparallax icon indicating copy to clipboard operation
jparallax copied to clipboard

Adding "move" event

Open ghost opened this issue 14 years ago • 3 comments

I was looking for simple "move" event without a complete freeze, like faking a mouse move - useful for controlling parallax position by buttons or triggered events. Here is the code (insert anywhere into big query on "layers" object):

return layers .bind("move", function(e){ var elem = jQuery(this), local = elem.data(plugin), mouse = local.mouse || local.freeze || global.mouse, x = regex.percent.exec(e.x) ? parseFloat(e.x.replace(/%$/, ''))/100 : (e.x || mouse.pointer[0]) , y = regex.percent.exec(e.y) ? parseFloat(e.y.replace(/%$/, ''))/100 : (e.y || mouse.pointer[1]);

    // Fake the mouse
    global.mouse.ontarget = false;
    global.port.pointer=[x,y];

    // Start animating
    elem
    .bind(frameEvent, global, update);
})

Arguments are the same as for "freeze". Decay was useless for me but it could be added easily.

ghost avatar Mar 01 '10 20:03 ghost

Ok.

My approach to this problem was to freeze and then unfreeze on mouseenter:

jQuery('.parallax-layer') .trigger({type: 'freeze', x: 2, y: 2});

jQuery('.parallax-mouseport') .bind('mouseenter', function(e){ jQuery('.parallax-layer').trigger('unfreeze'); });

However, I can see how a 'move' event would be a lot more concise. I think that can go in ...

Cheers!

stephband avatar Mar 01 '10 22:03 stephband

Note the code above suffers from Issue 5 - 0 values will not work.

stephband avatar Mar 01 '10 23:03 stephband

"Move" does not work in IE, it behave quirky. Only one animation step happens on move() call, so it takes multiple calls to actually move layers to final destination. Only IE's are affected, will investigate.

ghost avatar Mar 02 '10 10:03 ghost