How to change slide configuration parameters in javascript according to screen size without updating the page

Asked

Viewed 30 times

0

It is possible to land the configuration data on a slide with javascript programming according to the screen size without the need to update the page so that the javascript settings are updated to the resolution configured.

Because I am facing this dilemma, the script below works perfectly more as said, it is necessary to perform the page update when the user, this on a mobile device for example and ralize the change of the position of the screen from standing to lying or lying down to standing.

    <script>
$(document).ready(function(){
   var tam = $(window).width();
 
if (tam >= 470 && tam <= 770) {
// Adiciona as configurações de class caso o slide esteja ativo
const elemento2 = document.getElementById('elemento2');
if (elemento2.classList)
  elemento2.classList.add('seriestv');
else
  elemento2.className += ' seriestv';

// Modo de funcionamento do slide show ativado
$(".seriestv").slick({
dots: true,
infinite: true,
slidesToShow: 2,
slidesToScroll: 2,
autoplay: true,
autoplaySpeed:5000
});
}

else if (tam > 780 && tam <= 890) {
// Adiciona as configurações de class caso o slide esteja ativo
const elemento2 = document.getElementById('elemento2');
if (elemento2.classList)
  elemento2.classList.add('seriestv');
else
  elemento2.className += ' seriestv';

// Modo de funcionamento do slide show ativado
$(".seriestv").slick({
dots: true,
infinite: true,
slidesToShow: 3,
slidesToScroll: 3,
autoplay: true,
autoplaySpeed:5000
});
}

else if (tam <= 470) {

// Adiciona as configurações de class caso o slide esteja ativo
const elemento2 = document.getElementById('elemento2');
if (elemento2.classList)
  elemento2.classList.add('seriestv');
else
  elemento2.className += ' seriestv';

// Modo de funcionamento do slide show ativado
$(".seriestv").slick({
dots: true,
infinite: true,
slidesToShow: 1,
slidesToScroll: 1,
autoplay: true,
autoplaySpeed:5000
});

}

else if (tam >= 900){
// Adiciona as configurações de class caso o slide esteja ativo
const elemento2 = document.getElementById('elemento2');
if (elemento2.classList)
  elemento2.classList.add('seriestv');
else
  elemento2.className += ' seriestv';

// Modo de funcionamento do slide show ativado
$(".seriestv").slick({
dots: true,
infinite: true,
slidesToShow: 4,
slidesToScroll: 4,
autoplay: true,
autoplaySpeed:5000
});

}

});
</script>
  • you can "force" a slider refresh. If change the min or max value will force it to be updated, and then when doing this should take the changes in need to refresh the page

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.