e1commerce.com
Ask a question
  • New questions
  • With the answers
  • Unanswered
  1. Home
  2. javascript - Swiper js - How can i change the background color of the selected slide

673 votes
0 answers

javascript - Swiper js - How can i change the background color of the selected slide

Solution:

The easiest way is by the slide Active Class (API docs (https://swiperjs.com/swiper-api#param-slideActiveClass)):

.swiper-slide.swiper-slide-active{
  background: red;
}

Snippet:

var swiper = new Swiper(".swiper", {
  slidesPerView: 3,
  loop: true,
  spaceBetween: 30,
  pagination: {
    el: ".swiper-pagination",
    clickable: true,
  },
});
.swiper-slide.swiper-slide-active{
  background: red;
}
html,
body {
  position: relative;
  height: 100%;
}

body {
  background: #eee;
  font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: #000;
  margin: 0;
  padding: 0;
}

.swiper {
  width: 100%;
  height: 100%;
}

.swiper-slide {
  text-align: center;
  font-size: 18px;
  background: #fff;

  /* Center slide text vertically */
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
}

.swiper-slide img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

[scroll]{
  min-height: 100vh;
  background: gray;
}
<script src="https://cdn.jsdelivr.net/npm/swiper@8/swiper-bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/swiper@8/swiper-bundle.min.css" rel="stylesheet"/>

<div class="swiper mySwiper">
  <div class="swiper-wrapper">
    <div class="swiper-slide">Slide 1</div>
    <div class="swiper-slide">Slide 2</div>    
    <div class="swiper-slide">Slide 3</div>
    <div class="swiper-slide">Slide 4</div>
  </div>
  <div class="swiper-pagination"></div>
</div>

Undefined asked
2023-02-5


Source

Didn't find the answer?

Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Similar questions

Find the answer in similar questions on our website.

702 javascript - Swiper js - How can i change the background color of the selected slide
637 javascript - Shopify - How to change background color of a title on collection page by the product tag
111 reactjs - Can I use Next.js frontend app as Block in Shopify's Theme App Extensions instead of liquid?
94 javascript - Can no longer scroll with keys unless an element is selected
780 javascript - Safari debugging technique to get variable change(jQuery Plugin is reseted)
234 javascript - Redeclaration of Let error - How to find where it's being reassigned?
812 javascript - Slick Slider doesn't work with shopify dawn's product recommendation section
674 Shopify, Liquid, Alpine JS, Ajax can't redirect to cart after firing addToCart
405 Shopify Ajax API, Alpine JS, add user selected options to cart using Ajax
237 We can see the changes when we access it using Preview store but not live in shopify

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.







Latest questions:

194 Get product description with metafield in shopify

966 html - CSS animation looks wrong/broken in some places on iOS devices only?

29 Shopify refund amount wrong when refund in pending state (Admin REST API)

593 How to Add Fonts to the Shopify Admin

912 css selectors - Custom font for specific language shopify



© 2021-2023

E-mail: infot@e1commerce.com