Почему при переключении между слайдами пропускаются карточкиHtml

Программисты Html
Ответить
Anonymous
 Почему при переключении между слайдами пропускаются карточки

Сообщение Anonymous »

У меня есть 12 карточек, и я сделал так, чтобы по 3 карточки отображались для предварительного просмотра на настольном компьютере, по 2 карточки на планшете и по 1 карточке на мобильном телефоне. Теперь проблема в том, что он отлично работает в макете для настольного компьютера, но в макете для мобильных устройств и планшетов пропускает карточки и показывает только 6 карточек на мобильном телефоне и 8 карточек на макете планшета. Я проверил шаги и ширину, но похоже: «Я не могу найти решение здесь: мой код JavaScript

, мой HTML-код

и мой CSS
».slider {
position: relative;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
}
.slider_container {
display: flex;
overflow: hidden;
scroll-behavior: smooth;

}
.slider_nav_arrow{
width: 2rem;
}
.slider_nav{
background-color: transparent;
border: none;
margin: 1rem;
cursor: pointer;
}
.slider_container_box{
background-color: wheat;
min-width: 100%;
height: 20rem;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
padding: 1rem;
border-radius: 1rem;
gap: 1rem;
}
.slider_container_box p{
font-size: clamp(0.25rem, -0.632rem + 7.059vw, 1rem);
}
.slider_container_box_quotes{
width: 4rem;
align-self: self-start;
}
.slider_container_box_avatar-person{
display: flex;
justify-content: center;
align-items: center;
gap: 1.5rem;
align-self: self-start;
}
.slider_container_box_avatar-person img{
width: 3rem;
}
@media (min-width:700px){
.slider_container_box {
min-width: 50%;
}
.slider_container {
gap: 1rem;

}
}
@media (min-width:1100px){
.slider_container_box {
min-width: calc(100%/3);
}
.slider_container {
gap: 1rem;

}
}



Изображение



Изображение

"This website is incredibly well-structured and fast.
The animations feel smooth and professional, and the overall
UX makes our team want to redesign our own platform. Amazing work!"


Изображение

Aiden Clarke

Product Manager, NovaTech Labs




Изображение

"From the hero animation to the features section, the website feels
premium. It delivers exactly what modern SaaS brands need — clarity,
motion, and impact. Brilliant execution."


Изображение

Emily Zhao

Operations Director, SyncEdge Technologies




Изображение

"The smooth interactions and consistent styling show real craftsmanship.
You made a complex design look simple and enjoyable. Easily one of the
most polished templates I’ve seen."


Изображение

Daniel Reed

Product Manager, NovaTech Labs




Изображение

"I’m impressed by how everything responds perfectly on every device.
The counters, transitions, and content flow make the site feel alive.
Truly world-class work."


Изображение

Maya Hassan

Creative Strategist, PixelShift Studio




Изображение

"This template has the exact modern SaaS aesthetic clients want:
clean typography, strong visual hierarchy, and eye-catching animations.
You nailed the balance between beauty and usability."


Изображение

Oliver Grant

Senior Developer, CoreLink Software




Изображение

"The performance and code structure are solid. Lightweight, organized,
and easy to customize. It’s rare to find a template that looks this good
without sacrificing speed."


Изображение

Michael Carter

Founder, BrightPath Solutions




Изображение

“The attention to detail is incredible. Clean code, responsive
layout, and lightning-fast performance.”


Изображение

Sophia Martinez

Senior Software Engineer, CloudSphere




Изображение

“Our team was amazed at how polished and user-friendly
the website is. It elevated our brand instantly.”


Изображение

Noah Williams

Creative Director, FrameWorks Agency




Изображение

“I’ve tried many systems, but this one stands out.
Simple, organized, and extremely professional.”


Изображение

Isabella Chen

Business Analyst, DataCore




Изображение

“The UI design shows real expertise. Every interaction
feels smooth, natural, and intentional.”


Изображение

Benjamin Harris

E-Commerce Manager, UrbanMarket




Изображение

“This website helped us build trust with our investors.
Clean structure, bold visuals, and a great experience.”


Изображение

Harper Lewis

IT Consultant, TechAxis




Изображение

“Very easy to navigate and perfectly structured. It
communicates professionalism from the first glance.”


Изображение

Emma Johnson

Marketing Director, Visionary Media





Изображение



const track = document.querySelector('.slider_container')
const boxes = document.querySelectorAll('.slider_container_box')
const btnPrv = document.querySelector('.prev')
const btnNext = document.querySelector('.next')

let currentIndex = 0
function updateSlider(){
const cardWidth = boxes[0].getBoundingClientRect().width
const styles = window.getComputedStyle(track)
const gap = parseFloat(styles.columnGap || styles.gap)|| 0
const width = cardWidth + gap
track.scrollTo({
left: currentIndex * width,
behavior:'smooth'
})
}
function getCardsPerView(){
if(window.innerWidth >= 1100)return 3
if(window.innerWidth >= 700) return 2
return 1
}
btnNext.addEventListener('click',()=>{
const step = getCardsPerView()
const maxIndex = boxes.length - step
if(currentIndex < maxIndex){
currentIndex += step
updateSlider()
}
})
btnPrv.addEventListener('click',()=>{
const step = getCardsPerView()
if(currentIndex > 0){
currentIndex -= step
if(currentIndex < 0) currentIndex = 0
updateSlider()
}
})
window.addEventListener('resize',()=>{
updateSlider()
})



Подробнее здесь: https://stackoverflow.com/questions/798 ... een-slides
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Html»