2024-07-1311-19-21-ezgif.com-mute-video.mp4
A responsive parallax scrolling effect with a starry sky background, including interactive elements and zoom controls. This project is ideal for demonstrating parallax effects and interactive UI components.
- Parallax Scrolling: Multi-layered background that moves at different speeds to create a depth effect.
- Interactive Elements: Clickable points that display information in a card.
- Zoom Controls: Buttons to zoom in and out of the view.
- Position Controls: Sliders to move horizontally and vertically.
Check out the live demo on CodePen.
-
Clone the repository:
git clone https://github.com/yourusername/parallax-starry-sky.git cd parallax-starry-sky
-
Open
index.html
in your browser.
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Parallax Sternenhimmel</title>
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="controls.css">
</head>
<body>
<div class="scroll-container" id="scroll-container">
<div class="parallax-layer" id="layer1">
<img src="star_bg3.png" alt="Hintergrund 1" class="bg-image">
</div>
<div class="parallax-layer" id="layer2">
<img src="star_bg2.png" alt="Hintergrund 2" class="bg-image">
</div>
<div class="parallax-layer" id="layer3">
<img src="star_bg1.png" alt="Hintergrund 3" class="bg-image">
</div>
<div class="interactive-layer" id="interactive-layer">
<!-- Template Card -->
<div class="card" id="template-card" style="display: none;">
<div class="card-content"></div>
</div>
</div>
</div>
<div class="controls" id="controls">
<div class="position-info" id="position-info"></div>
<div class="control-sliders">
<input type="range" id="horizontal-slider" min="-50" max="50" step="1" value="0">
<input type="range" id="vertical-slider" min="-50" max="50" step="1" value="0" orient="vertical">
<div class="zoom-control">
<button class="zoom-button" data-zoom="0.5">--</button>
<button class="zoom-button" data-zoom="0.8">-</button>
<button class="zoom-button" data-zoom="1">o</button>
<button class="zoom-button" data-zoom="1.3">+</button>
<button class="zoom-button" data-zoom="1.6">++</button>
</div>
</div>
</div>
<script src="script.js"></script>
<script src="controls.js"></script>
</body>
</html>
The Parallax Starry Sky Project is a web application that demonstrates the use of parallax scrolling to create a visually engaging experience. It features multiple layers moving at different speeds to create a sense of depth, interactive elements represented by clickable points that open cards with information, and controls for navigation and zooming.
The project uses three background layers, each moving at different speeds to create the parallax effect. This effect is achieved by adjusting the transformation properties of each layer in response to user input.
-
Layer 1 (Farthest Background):
- Image:
star_bg3.png
- Transformation:
translate(${translateX * 0.5}px, ${translateY * 0.5}px) scale(${scale})
- Speed: Slowest
- Depth: Appears farthest away
- Image:
-
Layer 2 (Middle Background):
- Image:
star_bg2.png
- Transformation:
translate(${translateX * 0.3}px, ${translateY * 0.3}px) scale(${scale})
- Speed: Medium
- Depth: Intermediate
- Image:
-
Layer 3 (Closest Background):
- Image:
star_bg1.png
- Transformation:
translate(${translateX * 0.1}px, ${translateY * 0.1}px) scale(${scale})
- Speed: Fastest
- Depth: Appears closest
- Image:
The project includes 70 clickable points distributed randomly across the interactive layer. Each point represents a chat room and displays a card with more information when clicked.
-
Point Creation:
- Randomly positioned within the interactive layer.
- Size: 70px diameter.
- Styles: Slight transparency and pulsing animation for every 5th point.
-
Card Display:
- Each point opens a card displaying the chat room's title and description.
- Card position matches the point's position.
The project includes three types of navigation controls for user interaction:
-
Horizontal Slider:
- Adjusts the horizontal position of the layers.
- Range: -50 to 50 (scaled by a factor of 2).
-
Vertical Slider:
- Adjusts the vertical position of the layers.
- Range: -50 to 50 (scaled by a factor of 2).
-
Zoom Controls:
- Buttons for different zoom levels (
0.5
,0.8
,1
,1.3
,1.6
). - Changes the scale of all layers.
- Buttons for different zoom levels (
HTML Structure:
- Contains the layers, interactive elements, and control elements.
- Utilizes
div
elements for layers and controls, andimg
elements for background images.
CSS Styles:
- Styles for the body, layers, points, and controls.
- Keyframes for the pulsing animation of points.
JavaScript Functionality:
- Handles user input for dragging, touch movement, and wheel zooming.
- Updates transformations for parallax scrolling and zooming.
- Manages the display of cards when points are clicked.
The Parallax Starry Sky Project starts with setting up a multi-layered background using images of a starry sky. Each layer is given a different transformation speed to create the illusion of depth as the user navigates horizontally and vertically. Clickable points are then added to the interactive layer, each representing a chat room with detailed information displayed in a card upon interaction.
Navigation is facilitated through sliders for horizontal and vertical movement and buttons for zoom control, allowing users to explore the parallax environment intuitively. The project demonstrates the seamless integration of CSS, HTML, and JavaScript to create an interactive and visually appealing web application.
- GitHub Repository: Parallax Starry Sky
- Live Demo on CodePen: Parallax Starry Sky Demo
-
index.html Purpose: The main HTML file that structures the webpage. Contains the HTML elements for the parallax layers, interactive points, and control sliders/buttons.
-
styles.css Purpose: Defines the visual styles for the parallax layers, points, and general layout. Includes styles for the body, parallax layers, background images, points, and cards.
-
controls.css Purpose: Contains the styles specifically for the control elements. Includes styles for the control panel, position info, sliders, and zoom buttons.
-
script.js Purpose: Manages the main functionality of the parallax effect and interactive elements. Handles the parallax scrolling effect, card display on point click, and updating transformations.
-
controls.js Purpose: Handles the control elements for navigating and zooming. Manages the sliders for horizontal and vertical movement, and buttons for zooming in and out.
Function Name | File | Description |
---|---|---|
setTransform |
script.js | Updates the transformation properties (scale, translateX, translateY) of the parallax layers and interactive elements. |
updatePositionInfo |
script.js | Updates the on-screen display with the current position and zoom level. |
document.addEventListener('touchstart', function(e)) |
script.js | Captures the starting position for touch events and sets dragging to true. |
document.addEventListener('touchmove', function(e)) |
script.js | Calculates the change in position during touch events and updates the transformation. |
document.addEventListener('touchend', function()) |
script.js | Sets dragging to false when the touch ends. |
document.addEventListener('mousedown', function(e)) |
script.js | Captures the starting position for mouse events and sets dragging to true. |
document.addEventListener('mousemove', function(e)) |
script.js | Calculates the change in position during mouse events and updates the transformation. |
document.addEventListener('mouseup', function()) |
script.js | Sets dragging to false when the mouse button is released. |
document.addEventListener('mouseleave', function()) |
script.js | Sets dragging to false when the mouse leaves the window. |
document.addEventListener('wheel', function(e)) |
script.js & controls.js | Adjusts the scale property based on the wheel event to zoom in or out. |
document.addEventListener('DOMContentLoaded', function()) |
script.js | Initializes the points and attaches click event listeners to them for displaying cards. |
document.getElementById('horizontal-slider').addEventListener('input', function(e)) |
controls.js | Updates the horizontal translation based on the slider input value. |
document.getElementById('vertical-slider').addEventListener('input', function(e)) |
controls.js | Updates the vertical translation based on the slider input value. |
document.querySelectorAll('.zoom-button').forEach(button => button.addEventListener('click', function(e))) |
controls.js | Sets the scale property based on the zoom button clicked. |