Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

494
Views
How to set default active slide in Swiper JS

I have HTML

<div class="swiper-container instance-0" data-id="nav-slider">
  <ul class="swiper-wrapper nav-content__list">
    <li class=" swiper-slide nav-content__item">
      <a class=" link link--ms" href="/news-stories/stories">
        <span class="link__text">
         Stories
        </span>
      </a>
    </li>
    <li class=" swiper-slide nav-content__item">
      <a class=" link link--ms" href="/news-stories/multimedia">
        <span class="link__text">
          Multimedia
        </span>
      </a>
    </li>
    <li class=" swiper-slide nav-content__item">
      <a class=" link link--ms" href="/news-stories/press-releases">
        <span class="link__text">
          Press releases
        </span>
      </a>
    </li>
  </ul>
</div>

My js:

const $navSlider = $('[data-id="nav-slider"]');
      const $swiperInstances = [];
      const $currentPath = window.location.pathname;
      $navSlider.each(function (index, sliderElement) {
        const $this = $(this);
        $this.addClass(`instance-${index}`);
        $swiperInstances[index] = new Swiper(sliderElement, {
          slidesPerView: 'auto',
          watchOverflow: true,
          initialSlide: '2',
        });
      });

But initialSlide don't work for me. $swiperInstances[index].slideTo(2) don't work too

I need set the default item in the swiperslider

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you need to use .slideTo() in afterInit() event. documentation

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!