Skip to content

Commit

Permalink
Избавляется от мигания
Browse files Browse the repository at this point in the history
  • Loading branch information
TatianaFokina authored Jul 22, 2024
1 parent c758985 commit 6c8eaff
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion recipes/slider/demos/slider-demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@
}

.slide-img {
display: block;
inline-size: 100%;
block-size: 225px;
max-block-size: 225px;
object-fit: cover;
}

Expand All @@ -122,9 +124,14 @@
}

.slide {
display: none;
text-align: center;
}

.slide--active {
display: block;
}

@media (max-width: 768px) {
body {
padding: 30px;
Expand Down Expand Up @@ -189,6 +196,7 @@ <h2 id="item-4-label">Паттерн «Алый»</h2>
document.addEventListener('DOMContentLoaded', function () {
const slider = document.querySelector('.slider')
const slides = slider.querySelectorAll('.slide')
const activeSlides = 'slide--active'
const slideCount = slides.length
const controlButtons = slider.querySelectorAll('.button-radio')
const prevButton = slider.querySelector('.button-prev')
Expand All @@ -200,7 +208,11 @@ <h2 id="item-4-label">Паттерн «Алый»</h2>

function updateSlider() {
slides.forEach((slide, index) => {
slide.hidden = index !== currentSlide
if(index === currentSlide) {
slide.classList.add(activeSlides)
} else {
slide.classList.remove(activeSlides)
}
})

controlButtons.forEach((button, index) => {
Expand Down

0 comments on commit 6c8eaff

Please sign in to comment.