Skip to content

Commit 855bb20

Browse files
committed
add destroy functionality
1 parent 6f9b3b3 commit 855bb20

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

parallax.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,22 @@
311311
self.isBusy = false;
312312
});
313313
}
314+
},
315+
destroy: function(el){
316+
var i,
317+
parallaxElement = $(el).data('px.parallax');
318+
parallaxElement.$mirror.remove();
319+
for(i=0; i < this.sliders.length; i+=1){
320+
if(this.sliders[i] == parallaxElement){
321+
this.sliders.splice(i, 1);
322+
}
323+
}
324+
$(el).data('px.parallax', false);
325+
if(this.sliders.length === 0){
326+
$(window).off('scroll.px.parallax resize.px.parallax load.px.parallax');
327+
this.isReady = false;
328+
Parallax.isSetup = false;
329+
}
314330
}
315331
});
316332

@@ -330,7 +346,11 @@
330346
$this.data('px.parallax', new Parallax(this, options));
331347
}
332348
if (typeof option == 'string') {
333-
Parallax[option]();
349+
if(option == 'destroy'){
350+
Parallax['destroy'](this);
351+
}else{
352+
Parallax[option]();
353+
}
334354
}
335355
})
336356
};

0 commit comments

Comments
 (0)