function Logowall(element) {
this.element = element;
- this.items = element.children;
+ this.items = element.querySelectorAll(':scope .logo');
this.nbItems = this.items.length;
this.nbLines = 2;
this.perLine = this.nbItems / this.nbLines;
+ this.itemBaseWidth = 25;
this.index = 0;
this.transitioning = false;
this.init();
Logowall.prototype = {
init: function () {
this.initEvents();
+ this.setIndex(0, false);
},
initEvents: function () {
goPrev: function () {
this.go(this.index - 1, -1);
},
- go: function (newIndex, dir) {
+ go: function (newIndex) {
+ var $this = this;
+ if (this.transitioning) {
+ return;
+ }
+ this.transitioning = true;
+ this.setIndex(newIndex, true, function () {
+ $this.endTransition(newIndex);
+ });
+ },
+
+ setIndex: function (index, transition, callback) {
+ var visualIndex = -1 * (index + this.perLine);
+ var left = this.itemBaseWidth * visualIndex;
+
+ Array.prototype.forEach.call(this.element.querySelectorAll(':scope .line'), function (line) {
+ if (transition) {
+ line.classList.add('transition');
+ } else {
+ line.classList.remove('transition');
+ }
+ setTimeout(function () {
+ line.style.transform = "translateX(" + left + "%)";
+ }, 10);
+ });
+
+ if (callback !== undefined) {
+ setTimeout(function () {
+ callback()
+ }, 500);
+ }
+ },
+
+ endTransition: function (newIndex) {
+ this.index = this.normalizeIndex(newIndex);
+ if (this.index !== newIndex) {
+ this.setIndex(this.index, false);
+ }
+ this.transitioning = false;
+ },
+
+ normalizeIndex: function (index) {
+ var abs = Math.abs(index) % this.perLine;
+ if (index < 0) {
+ index = abs * -1;
+ } else {
+ index = abs;
+ }
+ return index;
},
resize: function () {
- var $this=this;
+ var $this = this;
var w = window,
d = document,
ww = w.innerWidth || e.clientWidth || g.clientWidth,
wh = w.innerHeight || e.clientHeight || g.clientHeight;
- var displayedCols = ww < 1024 ? (ww < 640 ? 2 : 3) : 4;
+ var lw = 25;
+ if (ww < 640) {
+ lw = 50;
+ } else if (ww < 1024) {
+ lw = 33.333;
+ }
+ var change = this.itemBaseWidth !== lw;
+ this.itemBaseWidth = lw;
+
+ if (change) {
+ this.setIndex(this.index, false);
+ }
var extras = this.element.querySelectorAll(':scope .extra');
Array.prototype.forEach.call(extras, function (node) {
});
Array.prototype.forEach.call(this.element.querySelectorAll(':scope .line'), function (line) {
- for (var i = 0; i < $this.perLine; i++) {
- var cloned = line.children[i].cloneNode(true);
- cloned.classList.add('extra');
- line.appendChild(cloned);
-
- cloned = line.children[i].cloneNode(true);
- cloned.classList.add('extra');
- line.appendChild(cloned);
+ for (var j = 0; j < 2; j++) {
+ for (var i = 0; i < $this.perLine; i++) {
+ var cloned = line.children[i].cloneNode(true);
+ cloned.classList.add('extra');
+ line.appendChild(cloned);
+ }
}
});
},
};
document.addEventListener('DOMContentLoaded', function () {
- console.log(':))');
window.wall = new Logowall(document.getElementsByClassName('logowall')[0]);
});