Remove a slide from a Swiper by class

Asked

Viewed 68 times

0

I have the following Swiper:

var swiperBanner = new Swiper('.swiper-container-banner', {
    slidesPerView: 1,
    speed: 1200,
    loop: true,
    grabCursor: true,
    freeMode: false,
    preventClicks: true,
    autoplay: {
        delay: 5000
    },
    pagination: {
        el: '.swiper-pagination',
        clickable: true
    }
});

in the slide images I have some with the class 'mobile' and others 'desktop', I would like to remove the mobile slides on larger screens, and the desktop on smaller screens, more I am not finding a way, already tried display: none but it didn’t work

  • Use Srcset on the slíder images I think you can solve to your bag the question of an image for each screen size

1 answer

0

You can use the CSS @media screen to define a rule of what you consider screen mobile and desktop. In the example below, I define screen desktop from 480px, therefore, in this rule, the screens considered mobile evening of 0px to 479px. Then just switch between display: none and display: block in the classes:

<style>
@media screen and (min-width: 480px) {
   .desktop{
      display: block;
   }
   .mobile{
      display: none;
   }
}

@media screen and (max-width: 479px) {
   .desktop{
      display: none;
   }
   .mobile{
      display: block;
   }
}
</style>
  • As I put it in the description, I’ve tried it this way, but it doesn’t work, I appreciate the try

Browser other questions tagged

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