-
Notifications
You must be signed in to change notification settings - Fork 187
#326: Solution for a Video Popup Modal #329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,134 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # 🎬 Video Modal Popup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| This project demonstrates how to create a **popup modal** that plays a **video trailer** when triggered by a button click. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| It’s perfect for **movie previews, product demos**, or any **interactive video showcase**. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## 📁 Project Structure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| video-modal/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| │ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ├── index.html # Main HTML structure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ├── style.css # Styling and responsive design | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ├── script.js # Event handling and video control logic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| └── README.md # Project documentation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## 🧩 Features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 🎥 Opens a modal when clicking the **Play Trailer** button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - ▶️ Plays an HTML5 video automatically inside the modal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - ❌ Includes a close button and closes on outside click | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 🔄 Automatically **pauses and resets** the video when closed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 📱 Fully **responsive** across all screen sizes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 💫 Smooth fade-in animation and hover effects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## ⚙️ How It Works (Detailed Explanation) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ### 🏗️ 1. index.html | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| The `index.html` file defines the structure of the webpage. It includes: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #### **Key Elements** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `<div class="movie-container">` — Wraps all content like the movie thumbnail, title, description, and button. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `<img>` — Displays the movie’s thumbnail or poster image. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `<h1>` — The movie title. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `<p>` — A short movie description or tagline. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `<button id="openModal">` — Button to trigger the modal popup. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `<button id="openModal">` — Button to trigger the modal popup. | |
| - `<button id="openModalBtn">` — Button to trigger the modal popup. |
Copilot
AI
Oct 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation shows the close button as a <span> element with class 'close', but the actual implementation uses a <button> element with class 'close-btn' and id 'closeModalBtn'.
| - `<span class="close">×</span>` — The close icon (×) used to close the modal. | |
| - `<button class="close-btn" id="closeModalBtn">×</button>` — The close icon (×) used to close the modal. |
Copilot
AI
Oct 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example code uses incorrect element IDs and class names that don't match the actual implementation. Should use 'openModalBtn', 'closeModalBtn', and 'trailer' respectively.
| const btn = document.getElementById("openModal"); | |
| const span = document.getElementsByClassName("close")[0]; | |
| const video = document.getElementById("trailerVideo"); | |
| const btn = document.getElementById("openModalBtn"); | |
| const span = document.getElementById("closeModalBtn"); | |
| const video = document.getElementById("trailer"); |
Copilot
AI
Oct 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation shows outdated code using onclick property and style.display, but the actual implementation uses addEventListener and CSS classes with classList.add('active').
| btn.onclick = function() { | |
| modal.style.display = "flex"; | |
| video.play(); | |
| } | |
| ``` | |
| When the **Play Trailer** button is clicked, this function makes the modal visible and starts playing the video. | |
| 3. **Close Modal Functionality** | |
| ```js | |
| span.onclick = function() { | |
| modal.style.display = "none"; | |
| video.pause(); | |
| video.currentTime = 0; | |
| } | |
| ``` | |
| When the close icon (×) is clicked, the modal hides, the video pauses, and the playback resets. | |
| 4. **Outside Click Close** | |
| ```js | |
| window.onclick = function(event) { | |
| if (event.target == modal) { | |
| modal.style.display = "none"; | |
| video.pause(); | |
| video.currentTime = 0; | |
| } | |
| } | |
| btn.addEventListener('click', function() { | |
| modal.classList.add('active'); | |
| video.play(); | |
| }); |
When the Play Trailer button is clicked, this function makes the modal visible and starts playing the video.
-
Close Modal Functionality
span.addEventListener('click', function() { modal.classList.remove('active'); video.pause(); video.currentTime = 0; });
When the close icon (×) is clicked, the modal hides, the video pauses, and the playback resets.
-
Outside Click Close
window.addEventListener('click', function(event) { if (event.target === modal) { modal.classList.remove('active'); video.pause(); video.currentTime = 0; } });
Copilot
AI
Oct 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation shows outdated code using window.onclick and style.display, but the actual implementation uses modal.addEventListener and classList.remove('active').
| btn.onclick = function() { | |
| modal.style.display = "flex"; | |
| video.play(); | |
| } | |
| ``` | |
| When the **Play Trailer** button is clicked, this function makes the modal visible and starts playing the video. | |
| 3. **Close Modal Functionality** | |
| ```js | |
| span.onclick = function() { | |
| modal.style.display = "none"; | |
| video.pause(); | |
| video.currentTime = 0; | |
| } | |
| ``` | |
| When the close icon (×) is clicked, the modal hides, the video pauses, and the playback resets. | |
| 4. **Outside Click Close** | |
| ```js | |
| window.onclick = function(event) { | |
| if (event.target == modal) { | |
| modal.style.display = "none"; | |
| video.pause(); | |
| video.currentTime = 0; | |
| } | |
| } | |
| btn.addEventListener("click", function() { | |
| modal.classList.add("active"); | |
| video.play(); | |
| }); |
When the Play Trailer button is clicked, this function makes the modal visible and starts playing the video.
-
Close Modal Functionality
span.addEventListener("click", function() { modal.classList.remove("active"); video.pause(); video.currentTime = 0; });
When the close icon (×) is clicked, the modal hides, the video pauses, and the playback resets.
-
Outside Click Close
modal.addEventListener("click", function(event) { if (event.target === modal) { modal.classList.remove("active"); video.pause(); video.currentTime = 0; } });
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Video Modal Popup</title> | ||
| <link rel="stylesheet" href="style.css" /> | ||
| </head> | ||
| <body> | ||
| <div class="movie-card"> | ||
| <img | ||
| src="https://m.media-amazon.com/images/I/81p+xe8cbnL._AC_SY679_.jpg" | ||
| alt="Movie Thumbnail" | ||
| class="thumbnail" | ||
| /> | ||
| <h2 class="movie-title">Inception</h2> | ||
| <p class="movie-description"> | ||
| A thief who enters the dreams of others to steal secrets from their | ||
| subconscious is given a chance to have his criminal record erased. | ||
| </p> | ||
| <button class="btn" id="openModalBtn">▶ Play Trailer</button> | ||
| </div> | ||
|
|
||
| <!-- Modal --> | ||
| <div class="modal" id="videoModal"> | ||
| <div class="modal-content"> | ||
| <h2 class="popup-title">Inception</h2> | ||
| <button class="close-btn" id="closeModalBtn">×</button> | ||
| <video id="trailer" controls> | ||
| <source | ||
| src="https://www.w3schools.com/html/mov_bbb.mp4" | ||
| type="video/mp4" | ||
| /> | ||
| Your browser does not support the video tag. | ||
| </video> | ||
| </div> | ||
| </div> | ||
|
|
||
| <script src="script.js"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| const openBtn = document.getElementById("openModalBtn"); | ||
| const closeBtn = document.getElementById("closeModalBtn"); | ||
| const modal = document.getElementById("videoModal"); | ||
| const video = document.getElementById("trailer"); | ||
|
|
||
| // Open modal | ||
| openBtn.addEventListener("click", () => { | ||
| modal.classList.add("active"); | ||
| video.play(); | ||
| }); | ||
|
|
||
| // Close modal | ||
| closeBtn.addEventListener("click", () => { | ||
| modal.classList.remove("active"); | ||
| video.pause(); | ||
| video.currentTime = 0; // reset to beginning | ||
| }); | ||
|
|
||
| // Close when clicking outside the video | ||
| modal.addEventListener("click", (e) => { | ||
| if (e.target === modal) { | ||
| modal.classList.remove("active"); | ||
| video.pause(); | ||
| video.currentTime = 0; | ||
| } | ||
| }); |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,177 @@ | ||||||||
| /* Base styles */ | ||||||||
| body { | ||||||||
| font-family: Arial, sans-serif; | ||||||||
| background: #ffffff; | ||||||||
| color: #fff; | ||||||||
|
||||||||
| color: #fff; | |
| color: #333; |
Copilot
AI
Oct 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space before opening brace. Should be .popup-title { to follow consistent CSS formatting.
| .popup-title{ | |
| .popup-title { |
Copilot
AI
Oct 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] CSS properties should be on separate lines for better readability and maintainability.
| top: 0; left: 0; | |
| top: 0; | |
| left: 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class name 'movie-container' doesn't match the actual implementation which uses 'movie-card'. This should be updated to reflect the correct class name.