M
M
Minusator2022-03-26 09:09:13
JavaScript
Minusator, 2022-03-26 09:09:13

How to upload other images on mobile devices in Slick Slider?

Good day

There is a Slick Slider on this markup

<div class="slider">
  <div class="slide">
    <picture>
      <source srcset="img/slides/slide-new-1.webp" type="image/webp">
      <source srcset="img/slides/slide-new-1.jpg" type="image/jpeg"> <img src="img/slides/slide-new-1.jpg"> 
                </picture>
  </div>
  <div class="slide">
    <picture>
      <source srcset="img/slides/slide-new-1.webp" type="image/webp">
      <source srcset="img/slides/slide-new-1.jpg" type="image/jpeg"> <img src="img/slides/slide-new-1.jpg"> 
                </picture>
  </div>
</div>


$('.slider').slick({
    infinite: true,
    slidesToShow: 1,
    slidesToScroll: 1,
    dots: true,
    arrows: false,
    autoplay: true,
    fade: true,
    autoplaySpeed: 5000
  });

How can I download other images on mobile devices?
I need exactly other images, since the slider is very narrow and nothing is visible when scaling.

Thanks for the help!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
ThunderCat, 2022-03-26
@Minusator

Piccha is just created for adaptability and maximum savings in traffic and resources.
1st option - use media queries for source: media="(max-width: 1200px)"
2nd option - srcset:

<srcset="image-small.png 320w, image-medium.png 800w, image-large.png 1200w">

read about responsive images

W
wonderingpeanut, 2022-03-26
@wonderingpeanut

const isSmallScreen = window.innerWidth < X;
const src = isSmallScreen ? smallImg : bigImg
const img = document.querySelector(myImg);
img.src = src;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question