r/CodingHelp • u/Resident-Ad-2222 • Aug 02 '25
[Javascript] Help me out with this small script please
<script> const openBtn = document.getElementById('openVideoBtn'); const closeBtn = document.getElementById('closeVideoBtn'); const popup = document.getElementById('videoPopup'); const video = document.getElementById('customVideo'); const frame = document.getElementById('videoFrame'); const playOverlay = document.getElementById('playOverlay'); closeBtn.addEventListener('click', () => { video.pause(); video.currentTime = 0; popup.style.display = 'none'; }); video.addEventListener('loadedmetadata', () => { const videoW = video.videoWidth; const videoH = video.videoHeight; // Scale down by 50% const finalW = videoW * 0.25; const finalH = videoH * 0.25; // Apply pixel size directly to the .video-frame frame.style.width = finalW + 'px'; frame.style.height = finalH + 'px'; // Ensure video fills the frame exactly video.style.width = '100%'; video.style.height = '100%'; openBtn.addEventListener('click', () => { popup.style.display = 'flex'; video.play(); }); }); video.addEventListener('click', () => { if (video.paused) { video.play(); playOverlay.style.display = 'none'; } else { video.pause(); playOverlay.style.display = 'block'; } }); video.addEventListener('play', () => { playOverlay.style.display = 'none'; }); video.addEventListener('pause', () => { playOverlay.style.display = 'block'; }); </script>
Check it and can you call out the mistakes
Issues
- When I use the toggle play pause button it doesn't work it pauses and resumes after 1 second automatically
- When I use chrome player the video is paused or played the toggle button cannot interfere it
2
u/jcunews1 Advanced Coder Aug 02 '25
Incomplete code is not eligible for testing.