jparallax icon indicating copy to clipboard operation
jparallax copied to clipboard

Adding and removing elements at runtime

Open 23tux opened this issue 11 years ago • 2 comments

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?

23tux avatar Sep 26 '12 14:09 23tux

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.

stephband avatar Sep 26 '12 19:09 stephband

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.

jecfmuller avatar Dec 02 '12 11:12 jecfmuller