jparallax
jparallax copied to clipboard
Adding and removing elements at runtime
I'm adding parallax to some elements at runtime. The first time, it works fine. But when I remove an element from the DOM, and I move my mouse outside the window and back, I'm getting this error:
Uncaught TypeError: Cannot read property 'freeze' of undefined
This is at line 391 in the jquery.parallax.js
And when I'm adding the element back to the DOM and call $(".bubbles").parallax()
it doesn't work anymore (the bubbles don't move).
Is it possible to provide a destroy function that the listeners are removed when an element is removed? Or any other solution?
If you check out the git branch '2.0' you will find a version without freeze events, but with an .unparallax() method for destroying the parallax.
Let me know how it goes. It has been used in production only a couple of times. On 26 Sep 2012 16:40, "Hubert Hölzl" [email protected] wrote:
I'm adding parallax to some elements at runtime. The first time, it works fine. But when I remove an element from the DOM, and I move my mouse outside the window and back, I'm getting this error:
Uncaught TypeError: Cannot read property 'freeze' of undefined
This is at line 391 in the jquery.parallax.js
And when I'm adding the element back to the DOM and call $(".bubbles").parallax() it doesn't work anymore (the bubbles don't move).
Is it possible to provide a destroy function that the listeners are removed when an element is removed? Or any other solution?
— Reply to this email directly or view it on GitHubhttps://github.com/stephband/jparallax/issues/47.
Hi, First of all : nice job ! When using your unparallax method like this : $(window).bind("resize", function () { jQuery('#parallax .parallax-layer') .unparallax(true) .parallax({ mouseport: jQuery('#parallax') }); }); I get an exception telling that elem is undefined in the unstyle function. It happens only when giving true to unparallax. I tried this because after calling unparallax, it flickers, seems like the layers would have been duplicated or something like that.