HOME PAGE
Expanding from the top-left corner. This is the home page content. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
This code creates an interactive, single-page application that uses CSS transitions to simulate page navigation by animating the size of different content containers. The structure consists of a set of navigation buttons and a main "canvas" area (.section) that acts as a container for four distinct content pages. Each page occupies the same space within the canvas but is anchored to a different corner—top-left, bottom-right, bottom-left, or top-right—using absolute positioning.
The magic behind the animation lies in the CSS transition property applied to the .page class. Initially, every page has a width and height of zero, making them invisible. When a user clicks a button, the associated JavaScript function triggers. First, it iterates through all existing pages and resets their dimensions to zero, effectively "closing" any currently open page. Because the transition is set to 0.6 seconds, this reset happens smoothly.
To ensure the animations don't overlap awkwardly, the JavaScript uses a setTimeout function with a 300- millisecond delay. This pause ensures that the closing phase of the transition is well underway before the selected page begins to expand. After the delay, the script sets the width and height of the target page to 600px by 400px, causing it to grow from its specific corner anchor to fill the entire container. This clean, programmatic approach allows for a fluid, "game-like" UI feel without needing to fetch new HTML files from a server.
To use this code, follow these steps:
1. How to Run It
2. How it Works (The Logic)
The code functions by managing the width and height of hidden div elements:
The JavaScript:
3. How to Customize
Add More Pages:
4. Important Notes
Expanding from the top-left corner. This is the home page content. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Expanding from the bottom-right corner. Learn more about us here.
Expanding from the bottom-left corner. Read our latest articles.
Expanding from the top-right corner. Get in touch with us.