Изменение цвета svg картинки, в зависимости от цвета фона
У меня такая проблема. На главной странице сайта, находится заглушка слайдер. Нужно сделать так, что бы цвет .logo и кнопки .menu менялся на конкретных слайдах, на чёрный цвет.
codepen: https://codepen.io/realHikkan/pen/LYRemqO
var swiper = new Swiper(".swiper-container", {
direction: "vertical",
slidesPerView: 1,
spaceBetween: 30,
autoplay: {
delay: 3500,
disableOnInteraction: false
},
mousewheel: true,
pagination: {
el: ".swiper-pagination",
clickable: true
}
});
@import url("https://fonts.googleapis.com/css2?family=Lato:wght@400;700&display=swap");
body {
font-family: 'Lato', sans-serif;
margin: 0;
}
button {
outline: none;
border: none;
cursor: pointer;
}
input {
outline: none;
}
input::placeholder {
opacity: 80%;
color: #fff;
}
.swiper-container {
position: absolute;
width: 100%;
height: 100%;
margin-left: auto;
margin-right: auto;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #000;
color: #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-pagination {
position: absolute;
left: 65.4px;
}
.swiper-pagination-bullet {
background-color: #f5f5f5 !important;
width: 12px;
height: 12px;
opacity: 1 !important;
}
.swiper-pagination-bullet-active {
background-color: #2b2b2b !important;
}
.swiper-container-vertical>.swiper-pagination-bullets .swiper-pagination-bullet {
margin: 16px 0;
display: block;
}
.nav {
position: fixed;
width: 87.5%;
height: 36px;
margin-top: 40px;
display: flex;
align-items: center;
z-index: 9999;
}
.menu {
width: 36px;
height: 36px;
margin-left: 65.4px;
background-image: url(https://www.neir-studio.ru/img/menu_hamburger-white.svg);
background-repeat: no-repeat;
background-position: center center;
background-color: transparent;
}
.logo {
margin-left: 64px;
}
.search {
margin-left: auto;
background: transparent;
padding-bottom: 8px;
width: 400px;
border: none;
border-bottom: 1px solid #fff;
font-family: "Lato", sans-serif;
font-size: 16px;
color: #fff;
}
.main-1 {
position: relative;
color: #ffffff;
min-height: 100vh;
background-image: url(../img/1.png);
background-repeat: no-repeat;
background-position: center 50%;
background-color: #000;
background-size: cover;
}
.main-4 {
position: relative;
color: #000;
min-height: 100vh;
background-color: #fff;
background-size: auto;
}
.main-5 {
position: relative;
color: #ffffff;
min-height: 100vh;
background-image: url(../img/4.png);
background-repeat: no-repeat;
background-position: top center;
background-color: #000;
background-size: auto;
}
.cart-btn {
position: fixed;
right: 0;
width: 120px;
height: 100%;
color: #fff;
text-transform: uppercase;
font-family: "Lato", sans-serif;
background: rgba(34, 34, 34, 0.92);
backdrop-filter: blur(36px);
z-index: 9999;
}
<nav>
<div class="nav">
<button type="button" class="menu"></button>
<a href="#"><img src="https://www.neir-studio.ru/img/logo-white.svg" alt="Saint Patron" class="logo"></a>
<input type="search" name="" value="" class="search" placeholder="Search">
</div>
</nav>
<a href="#"><button type="button" class="cart-btn">Cart (0)</button></a>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide main-1">Слайд 1</div>
<div class="swiper-slide main-4">Слайд 2</div>
<div class="swiper-slide main-5">Слайд 3</div>
</div>
<div class="swiper-pagination"></div>
</div>
<script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>
Ответы (2 шт):
Автор решения: letUser
→ Ссылка
Рекомендую Вам использовать подписку на событие смены слайда, добавив в функцию обработчик смены класса для кнопок и лого по индексу слайда:
const swiper = new Swiper(".swiper-container", {
direction: "vertical",
slidesPerView: 1,
spaceBetween: 30,
autoplay: {
delay: 3500,
disableOnInteraction: false
},
mousewheel: true,
pagination: {
el: ".swiper-pagination",
clickable: true
}
});
swiper.on('slideChange', () => console.log(swiper.activeIndex)); // здесь Ваша функция
Автор решения: Neomaster
→ Ссылка
У меня нет картинок для меню в другом цвете, сами вставите по аналогии.
var swiper = new Swiper(".swiper-container", {
direction: "vertical",
slidesPerView: 1,
spaceBetween: 30,
autoplay: {
delay: 3500,
disableOnInteraction: false
},
mousewheel: true,
pagination: {
el: ".swiper-pagination",
clickable: true
},
on: {
slideNextTransitionStart: function () {
if(document.getElementsByClassName('swiper-slide-active')[0].classList.contains('light')){
document.getElementsByClassName('search')[0].classList.add('light-search')
}else{
document.getElementsByClassName('search')[0].classList.remove('light-search')
}
},
slidePrevTransitionStart: function () {
if(document.getElementsByClassName('swiper-slide-active')[0].classList.contains('light')){
document.getElementsByClassName('search')[0].classList.add('light-search')
}else{
document.getElementsByClassName('search')[0].classList.remove('light-search')
}
}
}
});
@import url("https://fonts.googleapis.com/css2?family=Lato:wght@400;700&display=swap");
/* Добавлено */
nav .light-search{
border: none;
border-bottom: 1px solid black;
color: black;
}
nav .light-search::placeholder{
color: black;
}
body {
font-family: 'Lato', sans-serif;
margin: 0;
}
button {
outline: none;
border: none;
cursor: pointer;
}
input {
outline: none;
}
input::placeholder {
opacity: 80%;
color: #fff;
}
.swiper-container {
position: absolute;
width: 100%;
height: 100%;
margin-left: auto;
margin-right: auto;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #000;
color: #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-pagination {
position: absolute;
left: 65.4px;
}
.swiper-pagination-bullet {
background-color: #f5f5f5 !important;
width: 12px;
height: 12px;
opacity: 1 !important;
}
.swiper-pagination-bullet-active {
background-color: #2b2b2b !important;
}
.swiper-container-vertical
> .swiper-pagination-bullets
.swiper-pagination-bullet {
margin: 16px 0;
display: block;
}
.nav {
position: fixed;
width: 87.5%;
height: 36px;
margin-top: 40px;
display: flex;
align-items: center;
z-index: 9999;
}
.menu {
width: 36px;
height: 36px;
margin-left: 65.4px;
background-image: url(https://www.neir-studio.ru/img/menu_hamburger-white.svg);
background-repeat: no-repeat;
background-position: center center;
background-color: transparent;
}
.logo {
margin-left: 64px;
}
.search {
margin-left: auto;
background: transparent;
padding-bottom: 8px;
width: 400px;
border: none;
border-bottom: 1px solid #fff;
font-family: "Lato", sans-serif;
font-size: 16px;
color: #fff;
}
.main-1 {
position: relative;
color: #ffffff;
min-height: 100vh;
background-image: url(../img/1.png);
background-repeat: no-repeat;
background-position: center 50%;
background-color: #000;
background-size: cover;
}
.main-4 {
position: relative;
color: #000;
min-height: 100vh;
background-color: #fff;
background-size: auto;
}
.main-5 {
position: relative;
color: #ffffff;
min-height: 100vh;
background-image: url(../img/4.png);
background-repeat: no-repeat;
background-position: top center;
background-color: #000;
background-size: auto;
}
.cart-btn {
position: fixed;
right: 0;
width: 120px;
height: 100%;
color: #fff;
text-transform: uppercase;
font-family: "Lato", sans-serif;
background: rgba(34, 34, 34, 0.92);
backdrop-filter: blur(36px);
z-index: 9999;
}
<nav>
<div class="nav">
<button type="button" class="menu"></button>
<a href="#"><img src="https://www.neir-studio.ru/img/logo-white.svg" alt="Saint Patron" class="logo"></a>
<input type="search" name="" value="" class="search" placeholder="Search">
</div>
</nav>
<a href="#"><button type="button" class="cart-btn">Cart (0)</button></a>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide main-1 dark">Слайд 1</div>
<div class="swiper-slide main-4 light">Слайд 2</div>
<div class="swiper-slide main-5 dark">Слайд 3</div>
</div>
<div class="swiper-pagination"></div>
</div>
<script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>