From 284b93fa308b1e54e00c855bffbf644dd7e45c1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Mon, 3 May 2021 00:06:52 +0200 Subject: [PATCH] Fix: Design on phones or slower devices --- www/content-card-example.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/www/content-card-example.js b/www/content-card-example.js index c345a29..c689ee9 100644 --- a/www/content-card-example.js +++ b/www/content-card-example.js @@ -54,14 +54,19 @@ class ContentCardExample extends HTMLElement { //todo: run also on resize calculatePositions = () => { const _this = this; - //todo: figure out why timeout is needed here and do it properly - setTimeout(function () { + //todo: figure out why loop is needed here and do it properly + const setLeftOffsetsInterval = setInterval(() => { _this.movieElems = _this.getElementsByClassName("movieElem"); for (let i = 0; i < _this.movieElems.length; i++) { + if (_this.movieElems[i].offsetLeft === 0) { + break; + } else { + clearInterval(setLeftOffsetsInterval); + } _this.movieElems[i].style.left = _this.movieElems[i].offsetLeft + "px"; _this.movieElems[i].dataset.left = _this.movieElems[i].offsetLeft; } - }, 1); + }, 10); }; minimizeAll = () => {