jparallax
jparallax copied to clipboard
active/inactive events
is there currently a way of knowing if the parallax is currently in motion or not? I would like to change an element based on if any layers are currently in motion like so:
jQuery(function() { jQuery('#parallax') .inactive(function() { var src = 'car_stop.png'; jQuery('#car').attr("src", src); }) .active(function() { var src = 'car_go.png'; jQuery('#car').attr("src", src); }); });
any help is greatly appreciated!
That's a good question. The short answer is no - at least no way that is explicitly exposed.
I can have a look making this info available. I have to say, I don't like your suggested API, though. That would involve adding two new methods to the jQuery object, .active() and .inactive(), which have no meaning other than when called on a parallax layer. I would be more inclined to make some events available to bind to, something like:
jQuery('.parallax_layer') .on('parallaxstart', function(e) { // Layer has started moving }) .on('parallaxend', function(e) { // Layer has stopped moving });
The .on method with a parallaxstart and parallaxend event trigger is exactly what I am looking for. If this method could be available for the individual layers it would be even more powerful. This way we could access the parallax status of both the parallax container in general AND/OR a unique element.
Thanks for looking into this! -Baden