Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

158
Visualizações
jQuery update values on resize

I there,

I made a slider using Bootstrap and it works fine but I would like the values to change if the user rotates his tablet for example.

My Code:

var rtime;
var timeout = false;
var delta = 200;
$(window).resize(function() {
    rtime = new Date();
    if (timeout === false) {
        timeout = true;
        setTimeout(resizeend, delta);
    }
});
function resizeend() {
if (new Date() - rtime < delta) {
    setTimeout(resizeend, delta);
} else {
    timeout = false;
if($(".carousel-inner").scrollLeft() > 0)
{
  $("#lives_slider .carousel-inner").animate(
    { scrollLeft: 0 },
    600
  );
}

  var carouselWidth = $(".carousel-inner")[0].scrollWidth;
  var cardWidth = $(".carousel-item").width();
  var scrollPosition = 0;
    var multipleCardCarousel = document.querySelector(
      "#lives_slider" 
    );
    if (window.matchMedia("(min-width: 768px)").matches) {
      var carousel = new bootstrap.Carousel(multipleCardCarousel, {
        interval: false,
      });
      $("#lives_slider .carousel-control-next").on("click", function () {
        if (carouselWidth - scrollPosition - (cardWidth * 4) > 1){
          scrollPosition += cardWidth*4;
          console.log('Scroll : '+scrollPosition+'CardWidth : '+cardWidth);
          $("#lives_slider .carousel-inner").animate(
            { scrollLeft: scrollPosition },
            600
          );
        }
      });
      $("#lives_slider .carousel-control-prev").on("click", function () {
        if (scrollPosition > 0) {
          scrollPosition -= cardWidth*4;
          $("#lives_slider .carousel-inner").animate(
            { scrollLeft: scrollPosition },
            600
          );
        }
      });
    } else {
      $(multipleCardCarousel).addClass("slide");
    }
}               
}

resizeend();

After the resize, on click, the code is executed twice. Once with the old sizes, and once with the updated sizes.

A charitable soul to guide me ?

Thanks in advance !!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

up, anybody there? :/ just show me the path and i do it myself please

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda