Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda