Skip to content Skip to sidebar Skip to footer

How Stop Auto Play While Scroll Down

I Add Video In Header Which Played Automatically But I'm Unable To Stop Video When User Scroll Down To Page..

Solution 1:

Try this.

Your browser does not support the video tag. I suggest you upgrade your browser.

Solution 2:

You have to use Google youtube API for this purpose.

// 2. This code loads the IFrame Player API code asynchronously.// Youtuber APIvar tag = document.createElement('script');

      tag.src = "https://www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

      // 3. This function creates an <iframe> (and YouTube player)//    after the API code downloads.var player;
      functiononYouTubeIframeAPIReady() {
        player = newYT.Player('player', {
          height: '315',
          width: '560',
		  playerVars : {
                autoplay : 0,
                controls: 0,
                disablekb:0,
                modestbranding:1,
                showinfo:0

            },
          videoId: '3MGrgzTGdtE',
          events: {
			  
            'onReady': onPlayerReady,
            //'onStateChange': onPlayerStateChange
          }
        });
		player2 = newYT.Player('player2', {
          height: '315',
          width: '560',
		  playerVars : {
                autoplay : 0
            },
          videoId: '3MGrgzTGdtE',
          events: {
			  
            //'onReady': onPlayerReady2,//'onStateChange': onPlayerStateChange
          }
        });
      }

      // 4. The API will call this function when the video player is ready.functiononPlayerReady(event) {
          event.target.mute();
        //event.target.playVideo();
      }
	   
      functionstopVideo() {
        player.stopVideo();
      }
	  
	   $(window).scroll(function() {
		   var topOfOthnxtDiv = $("#parelaxhome").offset().top; 	
        $("#medicinediv").each( function() {
            if( ($(window).scrollTop() > $(this).offset().top)   ) {
               // $(this).css('opacity',1);
                player.playVideo();
            } if($(window).scrollTop() >= topOfOthnxtDiv)  {
                //$(this).css('opacity',0);
                player.stopVideo();
            }
        }); 
    });
	
	$(document).ready(function(e) {
        $('.pclose').click(function(){
			player2.stopVideo();
		})
		$('.clickpop').click(function(){
			player2.playVideo();
            player2.seekTo(0);
			player2.unMute();
		})
    });
<divclass="videodiv"><divid="myframe"><divid="play-video"></div><divid="player"></div></div>

Post a Comment for "How Stop Auto Play While Scroll Down"