Code

Play Background Video on Hover

Play a background video when a user hovers over the video on your Webflow site.

Play Background Video on Hover preview

Play a background video when a user hovers over the video on your Webflow site.

How to add it

  1. Add the Javascript code to the closing body custom code page settings
  2. Update the class name to your chosen class name

The code

Javascript
                      <!-- Add to body close section -->
<script>

var Webflow = Webflow || [];
Webflow.push(function() {
    // Change .video here to your video class
    var figure = $(".video").hover(function() {  
        $('video', this).get(0).play(); 
    }, function() {
        $('video', this).get(0).pause();
    }).each(function() {
        $('video', this).get(0).pause();
    });
});

</script>

                    

Browse similar code snippets

Categories

Language

More from Timothy Ricks

Profile →

Related Webflow questions

All answers →

Similar code snippets

All code snippets →