From a6648c7c2f82de95c6fc7fce76c81e4b04d60a49 Mon Sep 17 00:00:00 2001 From: Spedon Date: Thu, 4 May 2023 12:34:17 +0800 Subject: [PATCH] finish the basic scroll logic --- assets/ts/mobile.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/assets/ts/mobile.ts b/assets/ts/mobile.ts index e69de29..8f66752 100644 --- a/assets/ts/mobile.ts +++ b/assets/ts/mobile.ts @@ -0,0 +1,24 @@ +import { imagesDivNodes as images } from './elemGen' +import { imagesArrayLen } from './dataFetch' + +export const renderImages = (): void => { + images.forEach((img: HTMLImageElement, idx: number): void => { + const randomX: number = Math.floor(Math.random() * 35) + 2 + let randomY: number + + // random Y calculation + if (idx === 0) { + randomY = 68 + } else if (idx === 1) { + randomY = 44 + } else if (idx === imagesArrayLen - 1) { + randomY = 100 + } else { + randomY = Math.floor(Math.random() * 51) + 2 + } + + img.style.transform = `translate(${randomX}vw, -${randomY}%)` + img.style.marginTop = `${idx === 1 ? 70 : 0}vh` + img.style.visibility = 'visible' + }) +}