Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- $(function(){
- $(window).scroll(function(){
- var video = document.getElementById("video");
- var elemPos = video.getBoundingClientRect().bottom;
- var elemHeight = $('#video').height();
- var pos = elemHeight / 2;
- elemPos = elemPos - pos; // play video when it is at least halfway vissible
- pausePos = elemPos + pos + elemHeight; // pause video when scroll passes the video
- var p = document.documentElement.clientHeight;
- var check = $('.vid_pos_check').val();
- if (check == "false") {
- if(p>=elemPos ){
- $('#video').trigger('play');
- $('.vid_pos_check').val('true');
- console.log('video is halfway in view so it started');
- }
- }
- if(check == 'true'){
- if(p>=pausePos ){
- $('#video').trigger('pause');
- console.log('video out of view so it is paused');
- }
- }
- });
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement