BUGFIX: Fix issues if the DOM element is destroyed while the interval
is ongoing (in particular this was weird for Firefox)
This commit is contained in:
parent
7d6984a915
commit
47357136dc
|
@ -8,8 +8,12 @@
|
|||
};
|
||||
|
||||
LockOn.prototype.elementTop = function() {
|
||||
var offsetCalculator = this.options.offsetCalculator;
|
||||
return $(this.selector).offset().top - (offsetCalculator ? offsetCalculator() : 0);
|
||||
var offsetCalculator = this.options.offsetCalculator,
|
||||
selected = $(this.selector);
|
||||
|
||||
if (selected && selected.offset && selected.offset()) {
|
||||
return selected.offset().top - (offsetCalculator ? offsetCalculator() : 0);
|
||||
}
|
||||
};
|
||||
|
||||
LockOn.prototype.lock = function() {
|
||||
|
@ -26,6 +30,12 @@
|
|||
var top = self.elementTop(),
|
||||
scrollTop = $(window).scrollTop();
|
||||
|
||||
if (typeof(top) === "undefined") {
|
||||
$('body,html').off(scrollEvents)
|
||||
clearInterval(interval);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((top !== previousTop) || (scrollTop !== top)) {
|
||||
$(window).scrollTop(top);
|
||||
previousTop = top;
|
||||
|
|
Loading…
Reference in New Issue