Scroll triggered Fixed Video Player jQuery CSS3 - Download Scroll-triggered Fixed Video Player With jQuery And CSS3

Download Scroll-triggered Fixed Video Player With jQuery And CSS3

Posted on

This time I will share jQuery Plugin and tutorial about Scroll-triggered Fixed Video Player With jQuery And CSS3, hope it will help you in programming stack.

Scroll triggered Fixed Video Player jQuery CSS3 - Download Scroll-triggered Fixed Video Player With jQuery And CSS3
File Size: 2.01 KB
Views Total: 6288
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

A small jQuery script that automatically fixes the video player box at the bottom of the webpage as you scroll a certain distance from the top (the video player is scrolled out of the viewport). Just like the fixed video box as you seen in the Tumblr.com.

How to use it:

1. Embed an HTML5 video into the video box.

1 <div id="videoBox" class="box">
2   <video width="400" controls>
3     <source src="sample.mp4" type="video/mp4">
4     Your browser does not support HTML5 video.
5   </video>
6 </div>

2. Fix the video box when it’s scrolled out of view.

01 #videoBox.out {
02   position: fixed;
03   bottom: 0;
04   right: 0;
05   width: 300px;
06   z-index: 999;
07   animation: an 0.5s;
08 }
09  
10 #videoBox.in { animation: ac 1s; }

3. Place the necessary jQuery library in the document.

1 <script src="//code.jquery.com/jquery-3.2.0.slim.min.js"></script>

4. The jQuery script to detect the scroll event and toggle the CSS classes as you scroll down the webpage.

01 var ha = ( $('#videoBox').offset().top + $('#videoBox').height() );
02  
03 $(window).scroll(function(){ 
04  
05   if ( $(window).scrollTop() > ha + 500 ) {
06     $('#videoBox').css('bottom','0');
07   } else if ( $(window).scrollTop() < ha + 200) { 
08     $('#videoBox').removeClass('out').addClass('in');    
09   } else {      
10     $('#videoBox').removeClass('in').addClass('out');  
11     $('#videoBox').css('bottom','-500px');            
12   }; 
13  
14 });

This awesome jQuery plugin is developed by jlnljn. For more Advanced Usages, please check the demo page or visit the official website.

source : jqueryscript.net