Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I play HTML5 video from the start?

I followed a tutorial on YouTube that tells how to play a video on hover and pause it when the mouse is out. The code works like charm but I want to modify it. Currently, the video starts from the same place where we left but I want it to start from 0 every time the user hovers.

<script>
const clip = document.querySelectorAll('.clip');
for (let i = 0; i < clip.length; i++) {
    clip[i].addEventListener('mouseenter',
        function(e){
            clip[i].play()
        })
    clip[i].addEventListener('mouseout',
        function(e){
            clip[i].pause()
        })
}
</script>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Try

clip[i].currentTime=0;
clip[i].play();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading