Skip to content

Commit c04775a

Browse files
author
illarionov-company
committed
v1.0.3
1 parent 642ea0a commit c04775a

5 files changed

+63
-47
lines changed

lib/the-supersonic-plugin-for-scroll-based-animation.iife.js

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var TheSuperSonicPluginForScrollBasedAnimation = function() {
88
"use strict";
99
const Globals = {
1010
scroll: 0,
11+
screenHeight: 0,
1112
rafActive: true,
1213
rafId: 0,
1314
renderedInitially: false,
@@ -337,7 +338,7 @@ var TheSuperSonicPluginForScrollBasedAnimation = function() {
337338
this.start.updateLimits();
338339
this.end.updateLimits();
339340
if (this.end.top < this.start.top)
340-
this.end.top += window.innerHeight;
341+
this.end.top += Globals.screenHeight;
341342
this.helper.updateLimits();
342343
for (let property of this.properties) {
343344
property.updateLimits();
@@ -404,9 +405,9 @@ var TheSuperSonicPluginForScrollBasedAnimation = function() {
404405
this.domElement = domElement;
405406
}
406407
updateLimits() {
407-
this.top = this.domElement.getBoundingClientRect().top + Globals.scroll;
408+
this.top = ~~this.domElement.getBoundingClientRect().top + Globals.scroll;
408409
if (this.edge === "bottom")
409-
this.top -= window.innerHeight;
410+
this.top -= Globals.screenHeight;
410411
}
411412
}
412413
const _DriverHelper = class {
@@ -427,9 +428,9 @@ var TheSuperSonicPluginForScrollBasedAnimation = function() {
427428
let top = this.driver.start.top;
428429
let end = this.driver.end.top;
429430
if (this.driver.start.edge === "bottom")
430-
top += window.innerHeight;
431+
top += Globals.screenHeight;
431432
if (this.driver.end.edge === "bottom")
432-
end += window.innerHeight;
433+
end += Globals.screenHeight;
433434
this.domElement.style.setProperty("top", top + "px");
434435
this.domElement.style.setProperty("height", end - top + "px");
435436
}
@@ -478,7 +479,7 @@ var TheSuperSonicPluginForScrollBasedAnimation = function() {
478479
class TheSuperSonicPluginForScrollBasedAnimation2 {
479480
constructor(config) {
480481
__publicField(this, "observer", null);
481-
__publicField(this, "resizeWrapper", null);
482+
__publicField(this, "onResize", null);
482483
var _a;
483484
Globals.initConfig(config);
484485
this.initInstances();
@@ -526,40 +527,47 @@ var TheSuperSonicPluginForScrollBasedAnimation = function() {
526527
}
527528
}
528529
updateLimits() {
530+
this.updateScreenHeight();
529531
this.updateScroll();
530532
Driver.updateLimits();
531533
if (Globals.config.hooks.onUpdateLimits)
532534
Globals.config.hooks.onUpdateLimits();
533535
}
534536
updateScroll() {
535-
Globals.scroll = window.pageYOffset || window.scrollY || document.documentElement.scrollTop || document.body.scrollTop;
537+
Globals.scroll = window.scrollY || window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
538+
}
539+
updateScreenHeight() {
540+
const styles = {
541+
position: "absolute",
542+
left: "0",
543+
top: "0",
544+
height: "100vh",
545+
width: "1px",
546+
zIndex: "-1",
547+
visibility: "hidden"
548+
};
549+
let helper = document.createElement("div");
550+
for (let property in styles) {
551+
helper.style.setProperty(property, styles[property]);
552+
}
553+
document.body.appendChild(helper);
554+
Globals.screenHeight = helper.clientHeight;
555+
helper.remove();
536556
}
537557
addEventListeners() {
538-
this.resizeWrapper = debounce(() => {
558+
this.onResize = () => {
539559
this.updateLimits();
540560
this.render({ useActiveDrivers: false });
541-
});
542-
window.addEventListener("resize", this.onResize.bind(this));
561+
};
562+
window.addEventListener("resize", this.onResize);
543563
}
544564
removeEventListeners() {
545565
window.removeEventListener("resize", this.onResize);
546566
}
547-
onResize() {
548-
this.resizeWrapper();
549-
}
550567
}
551568
__publicField(TheSuperSonicPluginForScrollBasedAnimation2, "Driver", Driver);
552569
__publicField(TheSuperSonicPluginForScrollBasedAnimation2, "Property", Property);
553570
__publicField(TheSuperSonicPluginForScrollBasedAnimation2, "Element", Element);
554571
__publicField(TheSuperSonicPluginForScrollBasedAnimation2, "Globals", Globals);
555-
function debounce(func) {
556-
let timer;
557-
return () => {
558-
clearTimeout(timer);
559-
timer = setTimeout(() => {
560-
func.apply(this);
561-
}, 500);
562-
};
563-
}
564572
return TheSuperSonicPluginForScrollBasedAnimation2;
565573
}();

0 commit comments

Comments
 (0)