How to make video automatically stop playing when dropdown is folded up?

Ched Jose

I have a video inserted in a drop down window. So when the user drops the window, the video can be played. However, I want the video to stop playing automatically when the user folds up the drop down window without the need to click on "pause". Below you will find the html and css codes for the video within the dropdown window.

The html for video:

 <div class="wrapper">
<div class="videng">Click here to watch video</div>
<input id="_1" type="checkbox"> 
<label class="drop" for="_1">Watch here </label>  
<div class="run">

<video width="660" height="410" scrolling="no" controls >
<source src="videos/speaking/l2_snow.mp4" />
</video>

</div>
</div>

Here is the CSS

.collapse{
cursor: pointer;
display: block;
background: #999;
}
.collapse + input{
display: none; 
}
.collapse + input + div{
display:none;
}
.collapse + input:checked + div{
display:block;
}

.wrapper {
border:1px solid #999;
padding: 2px;
width:100%;
 }

Your help is greatly appreciated!

Théo

In this case you'll have to use a little of Javascript to pause the video because HTML/CSS can't do that. Here is the code to put between <script> and </script> tags. It'll pause the video element when the user uncheck the checkbox with id "_1".

document.getElementById("_1").addEventListener("click", function() {
    if(!document.getElementById("_1").checked) {
        document.querySelector("video").pause();
    }
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Jquery make Youtube video stop playing when clicking outside popup

From Dev

How to stop video playing in YTPlayerView inside UICollectionViewCell when scrolled?

From Dev

How do I stop JWPlayer from automatically playing the next video in the playlist?

From Dev

How do I stop JWPlayer from automatically playing the next video in the playlist?

From Dev

How to stop a flex video from playing on load

From Dev

How to load subtitles automatically by playing video

From Dev

how to stop dropdown menu child sliding up when clicked

From Dev

How to stop html5 video from playing when out of viewport?

From Dev

My livefeed reloads every 30 seconds. How stop refresh when playing video?

From Dev

how to stop the sound playing automaticly of a video when i launch html file on my browser?

From Dev

How to make the ListView scroll vertically up automatically when items are added?

From Dev

How to reset you-tube video after playing to stop recommadations

From Dev

ffmpeg: How to synchronize audio from overlayed video when that video is playing

From Dev

How to make the display NOT scaled when playing game?

From Dev

How can I make my caret stop from moving when clicking on dropdown menu?

From Dev

how to automatically record a video response after the video stops playing using flash

From Dev

Two folded polymorphism is weird, how to make it extensible?

From Dev

How to stop MPMusicPlayerController from playing when application terminate by user?

From Dev

How use 2 audio players and stop one when other is playing

From Dev

how to stop old song when new song is playing with Service

From Dev

How to automatically go to the next track when the one is currently playing ends?

From Dev

How to speed up video to make timelapse?

From Dev

Stop youtube video playing after tab exit

From Dev

How not to display the captions when video starts playing using videojs?

From Dev

How can I lock the keyboard and mouse when playing video

From Dev

How can I lock the keyboard and mouse when playing video

From Dev

How moving on to another ViewController when finished playing video?

From Dev

How to listen for when HTML5 video stops playing in jQuery?

From Dev

How to tell when youtube video stops playing from the terminal? macOS

Related Related

  1. 1

    Jquery make Youtube video stop playing when clicking outside popup

  2. 2

    How to stop video playing in YTPlayerView inside UICollectionViewCell when scrolled?

  3. 3

    How do I stop JWPlayer from automatically playing the next video in the playlist?

  4. 4

    How do I stop JWPlayer from automatically playing the next video in the playlist?

  5. 5

    How to stop a flex video from playing on load

  6. 6

    How to load subtitles automatically by playing video

  7. 7

    how to stop dropdown menu child sliding up when clicked

  8. 8

    How to stop html5 video from playing when out of viewport?

  9. 9

    My livefeed reloads every 30 seconds. How stop refresh when playing video?

  10. 10

    how to stop the sound playing automaticly of a video when i launch html file on my browser?

  11. 11

    How to make the ListView scroll vertically up automatically when items are added?

  12. 12

    How to reset you-tube video after playing to stop recommadations

  13. 13

    ffmpeg: How to synchronize audio from overlayed video when that video is playing

  14. 14

    How to make the display NOT scaled when playing game?

  15. 15

    How can I make my caret stop from moving when clicking on dropdown menu?

  16. 16

    how to automatically record a video response after the video stops playing using flash

  17. 17

    Two folded polymorphism is weird, how to make it extensible?

  18. 18

    How to stop MPMusicPlayerController from playing when application terminate by user?

  19. 19

    How use 2 audio players and stop one when other is playing

  20. 20

    how to stop old song when new song is playing with Service

  21. 21

    How to automatically go to the next track when the one is currently playing ends?

  22. 22

    How to speed up video to make timelapse?

  23. 23

    Stop youtube video playing after tab exit

  24. 24

    How not to display the captions when video starts playing using videojs?

  25. 25

    How can I lock the keyboard and mouse when playing video

  26. 26

    How can I lock the keyboard and mouse when playing video

  27. 27

    How moving on to another ViewController when finished playing video?

  28. 28

    How to listen for when HTML5 video stops playing in jQuery?

  29. 29

    How to tell when youtube video stops playing from the terminal? macOS

HotTag

Archive