@adoratorio/hades
Advanced tools
Comparing version 0.1.31 to 0.2.0
@@ -30,2 +30,3 @@ import Aion from '@adoratorio/aion'; | ||
sections: string | boolean; | ||
loop: boolean; | ||
autoplay: boolean; | ||
@@ -32,0 +33,0 @@ aion: Aion | null; |
@@ -58,2 +58,3 @@ "use strict"; | ||
sections: false, | ||
loop: false, | ||
autoplay: true, | ||
@@ -95,2 +96,5 @@ aion: null, | ||
} | ||
if (this.options.loop && !this.options.sections && !this.options.infiniteScroll) { | ||
throw new Error('Cannot have a loop without sections and infiniteScroll enabled'); | ||
} | ||
// If sections are setted load the nodes | ||
@@ -169,8 +173,10 @@ if (this.virtual && this.options.sections) { | ||
if (this.virtual && this.options.sections) { | ||
var sectionsWidth_1 = []; | ||
var sectionsHeight_1 = []; | ||
var sectionsWidth_1 = []; | ||
var sectionLeft_1 = []; | ||
this.sections.forEach(function (section) { | ||
var _a = section.getBoundingClientRect(), width = _a.width, height = _a.height; | ||
var _a = section.getBoundingClientRect(), width = _a.width, height = _a.height, left = _a.left; | ||
sectionsWidth_1.push(width); | ||
sectionsHeight_1.push(height); | ||
sectionLeft_1.push(left); | ||
}); | ||
@@ -182,14 +188,48 @@ this.sections.forEach(function (section, index) { | ||
for (var i = 0; i < index; i++) { | ||
prevSectionsWidth += sectionsWidth_1[i]; | ||
prevSectionsHeight += sectionsHeight_1[i]; | ||
prevSectionsWidth += sectionsWidth_1[i]; | ||
} | ||
// Check if we need to translate this section | ||
if ((_this.prevAmount.y > (prevSectionsHeight - window.innerHeight) && | ||
((prevSectionsHeight + rect.height) - window.innerHeight) > 0) || | ||
(_this.prevAmount.x > (prevSectionsWidth - window.innerWidth) && | ||
((prevSectionsWidth + rect.width) - window.innerWidth) > 0)) { | ||
var px = _this.options.lockX ? 0 : _this.amount.x * -1; | ||
var py = _this.options.lockY ? 0 : _this.amount.y * -1; | ||
section.style.transform = "translate3d(" + px + "px, " + py + "px, 0px)"; | ||
if (!_this.options.loop) { | ||
if (!_this.options.lockX && | ||
_this.prevAmount.x > prevSectionsWidth - window.innerWidth && | ||
_this.prevAmount.x < prevSectionsWidth + rect.width) { | ||
var px = _this.options.lockX ? 0 : _this.amount.x * -1; | ||
section.style.transform = "translate3d(" + px + "px, 0px, 0px)"; | ||
} | ||
if (!_this.options.lockY && | ||
_this.prevAmount.y > prevSectionsHeight - window.innerHeight && | ||
_this.prevAmount.y < prevSectionsHeight + rect.height) { | ||
var py = _this.options.lockY ? 0 : _this.amount.y * -1; | ||
section.style.transform = "translate3d(0px, " + py + "px, 0px)"; | ||
} | ||
} | ||
if (_this.options.loop) { | ||
if (!_this.options.lockX) { | ||
var blockSize = _this.boundries.max.x + window.innerWidth; | ||
var multiplier = Math.floor(_this.prevAmount.x / blockSize); | ||
var leftSide = _this.prevAmount.x - blockSize * multiplier; | ||
if (prevSectionsWidth + rect.width > leftSide) { | ||
var px = _this.options.lockX ? 0 : (_this.amount.x - multiplier * blockSize) * -1; | ||
section.style.transform = "translate3d(" + px + "px, 0px, 0px)"; | ||
} | ||
else { | ||
var px = _this.options.lockX ? 0 : (_this.amount.x - multiplier * blockSize - _this.boundries.max.x - window.innerWidth) * -1; | ||
section.style.transform = "translate3d(" + px + "px, 0px, 0px)"; | ||
} | ||
} | ||
if (!_this.options.lockY) { | ||
var blockSize = _this.boundries.max.y + window.innerHeight; | ||
var multiplier = Math.floor(_this.prevAmount.y / blockSize); | ||
var topSide = _this.prevAmount.y - blockSize * multiplier; | ||
if (prevSectionsHeight + rect.height > topSide) { | ||
var py = _this.options.lockY ? 0 : (_this.amount.y - multiplier * blockSize) * -1; | ||
section.style.transform = "translate3d(0px, " + py + "px, 0px)"; | ||
} | ||
else { | ||
var py = _this.options.lockY ? 0 : (_this.amount.y - multiplier * blockSize - _this.boundries.max.y - window.innerHeight) * -1; | ||
section.style.transform = "translate3d(0px, " + py + "px, 0px)"; | ||
} | ||
} | ||
} | ||
}); | ||
@@ -196,0 +236,0 @@ } |
{ | ||
"name": "@adoratorio/hades", | ||
"version": "0.1.31", | ||
"version": "0.2.0", | ||
"description": "A smooth scrollbar based on Hermes, scroll down 'till hell", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
43765
852