Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
Autoplay Youtube Video and Pause on Scroll

I have a specific Autoplay youtube script, which is quite efficient because it also works on mobile. However, I am trying to pause this Youtube Video when the user scrolls the video outside of the viewport - this way if they play another video; they are not playing simultaneously. Another solution would be to simply pause one video when another is started.

Current Autoplay script

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

var players;
function onYouTubePlayerAPIReady() {
    var players = document.querySelectorAll('.no-sound div')
    for (var i = 0; i < players.length; i++) {
        new YT.Player(players[i], {
    playerVars: {
        'autoplay': 1,
        'playsinline': 1},
        events: {
        'onReady': onPlayerReady
    },
    videoId: players[i].dataset.id
});
    }
}
      function onPlayerReady(event) {
        event.target.mute();
        event.target.playVideo();
      }

The video is embedded in the page like so:

<div id="videoWrapper" class="no-sound">
    <div data-id="#"></div>
</div>
about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!