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

203
Vistas
How can I get this video to scroll smoothly?

The video has a high keyframe interval (set at 1) so seeking isn't a problem. It scrolls smoothly on my localhost, however it's lagging in production. Here's a demo. Any help would be greatly appreciated as I've been stuck on this for a while.

My goal is to make the video to scroll smoothly and without lag. I'm using a fetch request so that I can download the whole video first to help with the smoothness however it didn't seem to work. Here's my code:

$(document).ready(function () {

  var vid = $('#v0');
  var url = "videos/video.mp4";
  var intro = $("#intro");
  var spinner = $(".spinner-border").closest("div");
  var checkOnce = false;
  var videoLength = $('.heading').length * 2;

  vid.hide();
  spinner.hide();

  var xhr = new XMLHttpRequest();
  xhr.open("GET", url, true);
  xhr.responseType = "arraybuffer";

  xhr.onload = function (oEvent) {
    var blob = new Blob([oEvent.target.response], { type: "video/mp4" });
    vid.src = URL.createObjectURL(blob);

    vid[0].play();

    // required to remove the fixed height
    intro.css('marginBottom', vid.height());

    // refresh video frames on interval for smoother playback
    setInterval(function () {
      vid[0].pause();
      vid[0].currentTime = (window.pageYOffset / (intro.height() / videoLength));

      // change video position to fixed or relative when scrolling past container
      if ($(window).scrollTop() >= intro.offset().top + intro.outerHeight() - window.innerHeight + vid.height()) {
        if (checkOnce == false) {
          vid.css('position', 'relative');
          intro.css('marginBottom', 0);
          checkOnce = true;
        }
      } else {
        if (checkOnce == true) {
          intro.css('marginBottom', vid.height());
          vid.css('position', 'fixed');
          checkOnce = false;
        }
      }
    }, 40);
  };

  xhr.onprogress = function (oEvent) {
    if (oEvent.lengthComputable) {
      var progress = oEvent.loaded / oEvent.total;
      if (progress < 1) {
        spinner.show();
        vid.fadeOut();
      } else {
        spinner.hide();
        vid.fadeIn();
      }
    }
  }

  xhr.send();
});
about 4 years ago · Juan Pablo Isaza
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