Advertisement
Guest User

Untitled

a guest
Jul 13th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. <script type="text/javascript">
  2. $('#home').YTPlayer({
  3. fitToBackground: true,
  4. videoId: 'o5UFpWgV30o',
  5. mute: false,
  6. callback: function(){
  7. //stop video when offsceen
  8. var wind = $(window);
  9. var height = wind.height();
  10. var yt = $('#home').data("ytPlayer").player;
  11. wind.on("scroll", function(){
  12.  
  13. //check if the user scrolled offscreen -> the size of the window
  14. var scroll = $(this).scrollTop();
  15.  
  16. if(scroll > height){
  17. yt.pauseVideo();
  18. }else{
  19. yt.playVideo();
  20. }
  21.  
  22. });
  23. wind.on("resize", function(){
  24. height = wind.height(); //update height when the window is resized
  25. });
  26. }
  27. });
  28. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement