HTML Explanation
01
The HTML here serves as the backbone for a 3D grid layout.
02
The main elements are a <header> for the page title and description, and a <div class="cards">, which will hold card elements created by JavaScript.
03
Linking styles.css and script.js ensures that the structure will be styled and interactive.
04
This setup allows JavaScript to dynamically generate elements within the cards container, keeping HTML flexible and uncluttered.
CSS Explanation
01
The CSS sets up a grid that transforms into an isometric, 3D style.
02
.cards uses a grid layout, defining rows and columns for card placement.
03
By rotating the grid (rotateX(45deg) and rotateZ(45deg)), it visually “tilts” the grid, giving it that isometric look.
04
Variables like --cardW and --cardH make adjusting card sizes easy throughout the CSS. --cardZInc controls the spacing between 3D layers within each card stack, making it easy to manage the depth.
05
Each card has layered elements (e.g., .top, .mid-top, .bottom) with different translateZ values. These layers, combined with shadows, create a realistic 3D stack. When hovering over a card, the layers appear to separate slightly, enhancing the depth effect.
Javascript Explanation
01
The script uses a while loop to create 36 card stacks, each containing four 3D layers (top, mid-top, mid-bottom, bottom) and a shadow.
02
By assigning images from an array, each card gets a unique background, creating a visually varied grid. These cards are added directly into the HTML’s .cards container.
03
The scrollGrid function adjusts the card grid’s position based on how much the user scrolls.
04
It calculates a transY value that moves the grid vertically, making the layout responsive to scrolling and giving an animated 3D experience.
05
The script also listens for page resizing and scrolling, calling scrollGrid each time to keep the layout consistent across different screen sizes and scrolling actions.