@@ -40,7 +40,7 @@ The `index.html` file defines the structure of the webpage. It includes:
4040- ` <p> ` — A short movie description or tagline.
4141- ` <button id="openModalBtn"> ` — Button to trigger the modal popup.
4242- ` <div id="videoModal" class="modal"> ` — The modal container that holds the video player.
43- - ` <span class="close" >×</span > ` — The close icon (×) used to close the modal.
43+ - ` <button class="close-btn" id="closeModalBtn" >×</button > ` — The close icon (×) used to close the modal.
4444- ` <video> ` — The HTML5 video element that plays the trailer inside the modal.
4545
4646These elements are organized in a clean hierarchy to ensure readability and easy maintenance.
@@ -91,41 +91,43 @@ The `script.js` file manages all interactions between the user and the modal.
9191#### **Functions Explained**
92921. **Element References**
9393 ```js
94- const modal = document.getElementById("videoModal");
95- const btn = document.getElementById("openModalBtn");
96- const span = document.getElementById("closeModalBtn");
97- const video = document.getElementById("trailer");
94+ const openBtn = document.getElementById("openModalBtn");
95+ const closeBtn = document.getElementById("closeModalBtn");
96+ const modal = document.getElementById("videoModal");
97+ const video = document.getElementById("trailer");
98+
9899 ```
99100 These lines reference the key DOM elements for manipulation.
100101
1011022. **Open Modal Functionality**
102103 ```js
103- btn.onclick = function() {
104- modal.style.display = "flex";
105- video .play();
106- }
104+ openBtn.addEventListener("click", () => {
105+ modal.classList .add("active");
106+ video .play();
107+ });
108+
107109 ```
108110 When the ** Play Trailer** button is clicked, this function makes the modal visible and starts playing the video.
109111
1101123 . ** Close Modal Functionality**
111113 ``` js
112- span . onclick = function () {
113- modal .style . display = " none " ;
114- video .pause ();
115- video .currentTime = 0 ;
116- }
114+ closeBtn . addEventListener ( " click " , () => {
115+ modal .classList . remove ( " active " ) ;
116+ video .pause ();
117+ video .currentTime = 0 ; // reset to beginning
118+ });
117119 ```
118120 When the close icon (×) is clicked, the modal hides, the video pauses, and the playback resets.
119121
1201224 . ** Outside Click Close**
121123 ``` js
122- window . onclick = function ( event ) {
123- if (event .target == modal) {
124- modal .style . display = " none " ;
125- video .pause ();
126- video .currentTime = 0 ;
127- }
128- }
124+ modal . addEventListener ( " click " , ( e ) => {
125+ if (e .target = == modal) {
126+ modal .classList . remove ( " active " ) ;
127+ video .pause ();
128+ video .currentTime = 0 ;
129+ }
130+ });
129131 ```
130132 This ensures that clicking ** outside the modal content** also closes the popup and stops the video.
131133
0 commit comments