Стрелочки слайдера не работают. Ошибок никаких нет
Почему не работает переключение - я не понимаю. Функции следующий и назад написаны. Я их в код установил. Ошибок никаких нету. Проверял с выводом в консоль сообщения и цифры, всё работало +1 -1 и так далее. Но слайдер не переключается. И вообще никак не реагирует.
import React, {
useState
} from 'react';
const ShowCase = () => {
const [activeSlide, setActiveSlide] = useState(0);
const handlePrev = () => setActiveSlide(activeSlide - 1);
const handleNext = () => setActiveSlide(activeSlide + 1);
return ( <
div className = 'Showcase_item__ajKek' >
<
div >
<
div className = 'common_line__9RJLR common_line_type_promo-editors___GaUP PromoVideoline_line__iqVKv PromoVideoline_line_type_promo-editors__0Mf2V'
data - gtm - vis - first - on - screen11350452_351 = "939"
data - gtm - vis - total - visible - time11350452_351 = "100"
data - gtm - vis - has - fired11350452_351 = "1" >
<
div className = 'Header_header__YhTu_ PromoVideoline_header__v2m27' >
<
div className = 'Header_wrapper__rgWJb' >
<
h2 className = 'Header_title__n1TZ2' > Новое в Flixo < /h2> <
/div> <
/div> <
div className = 'Slider_slider__RbzAd'
style = {
{
'--slideToShow': '5',
'--slides-offset': '16px'
}
} >
<
div className = 'Slider_btn__B8Qtp Slider_btn_prev__xfwu8 PromoVideoline_sliderButton__7NopD Slider_btn_visible__LJrxs'
onClick = {
handlePrev
}
style = {
{
backgroundImage: `url(${left})`
}
} >
<
div className = 'Slider_btnArrow__Aafu_' > < /div> <
/div> <
div className = 'Slider_btn__B8Qtp Slider_btn_next__xB4sg PromoVideoline_sliderButton__7NopD Slider_btn_visible__LJrxs'
onClick = {
handleNext
}
style = {
{
backgroundImage: `url(${right})`
}
} >
<
div className = 'Slider_btnArrow__Aafu_' > < /div> <
/div> <
div className = 'Slider_container__v97Np PromoVideoline_sliderContainer__RcVni' >
<
div className = 'Slider_wrapper__O8hJs PromoVideoline_sliderWrapper__rq6Hq'
style = {
{
transform: 'translateX(0px)'
}
} >
<
div data - slideindex = "0"
className = 'Slider_slide__prVHT Slider_slide_in_view___jKkg' >
<
a className = 'common_card_type_promo-editors__39291 UniversalPromoCard_card__XDJE_'
href = "#"
style = {
{
zIndex: 1000
}
} >
<
div className = 'UniversalPromoCard_imageWrapper__81un3'
style = {
{
color: 'rgb(31, 33, 37)'
}
} >
<
div className = 'UniversalPromoCard_imageWrapper__UD20K'
style = {
{
backgroundImage: `url(${image1})`,
clipPath: 'polygon(0% 5%, 100% 0%, 100% 100%, 0% 100%)'
}
} >
<
div className = 'UniversalPromoCard_ageRestrictions__wKovT' > 18 + < /div> <
div className = 'UniversalPromoCard_gradient__Oyt0j UniversalPromoCard_gradient_preset_layered-poster__VCnPW UniversalPromoCard_gradient_with_shadow__bk_Bw UniversalPromoCard_gradient_with_accent__CDZ8Z UniversalPromoCard_gradient_with_cornerShadow__l90XL' > < /div> <
img className = 'UniversalPromoCard_logo__kakl2'
src = {
logo1
}
alt = ""
style = {
{
marginTop: `100%`,
width: '100%',
height: 'auto'
}
}
/> <
/div> <
/div> <
span className = 'visually-hidden' > HALO < /span> <
/a> <
/div> <
div data - slideindex = "1"
className = 'Slider_slide__prVHT Slider_slide_in_view___jKkg' >
<
a className = 'common_card_type_promo-editors__39291 UniversalPromoCard_card__XDJE_'
href = "#"
style = {
{
zIndex: 999
}
} >
<
div className = 'UniversalPromoCard_imageWrapper__81un3'
style = {
{
color: 'rgb(31, 33, 37)'
}
} >
<
div className = 'UniversalPromoCard_imageWrapper__UD20K'
style = {
{
backgroundImage: `url(${image2})`,
clipPath: 'polygon(0% 5%, 100% 0%, 100% 100%, 0% 100%)'
}
} >
<
div className = 'UniversalPromoCard_ageRestrictions__wKovT' > 18 + < /div> <
div className = 'UniversalPromoCard_gradient__Oyt0j UniversalPromoCard_gradient_preset_layered-poster__VCnPW UniversalPromoCard_gradient_with_shadow__bk_Bw UniversalPromoCard_gradient_with_accent__CDZ8Z UniversalPromoCard_gradient_with_cornerShadow__l90XL' > < /div> <
img className = 'UniversalPromoCard_logo__kakl2'
src = {
logo2
}
alt = ""
style = {
{
marginTop: `90%`,
width: '100%',
height: 'auto'
}
}
/> <
/div> <
/div> <
span className = 'visually-hidden' > Призраки < /span> <
/a> <
/div> <
div data - slideindex = "2"
className = 'Slider_slide__prVHT Slider_slide_in_view___jKkg' >
<
a className = 'common_card_type_promo-editors__39291 UniversalPromoCard_card__XDJE_'
href = "#"
style = {
{
zIndex: 998
}
} >
<
div className = 'UniversalPromoCard_imageWrapper__81un3'
style = {
{
color: 'rgb(31, 33, 37)'
}
} >
<
div className = 'UniversalPromoCard_imageWrapper__UD20K'
style = {
{
backgroundImage: `url(${image3})`,
clipPath: 'polygon(0% 5%, 100% 0%, 100% 100%, 0% 100%)'
}
} >
<
div className = 'UniversalPromoCard_ageRestrictions__wKovT' > 18 + < /div> <
div className = 'UniversalPromoCard_gradient__Oyt0j UniversalPromoCard_gradient_preset_layered-poster__VCnPW UniversalPromoCard_gradient_with_shadow__bk_Bw UniversalPromoCard_gradient_with_accent__CDZ8Z UniversalPromoCard_gradient_with_cornerShadow__l90XL' > < /div> <
img className = 'UniversalPromoCard_logo__kakl2'
src = {
logo3
}
alt = ""
style = {
{
marginTop: `100%`,
width: '100%',
height: 'auto'
}
}
/> <
/div> <
/div> <
span className = 'visually-hidden' > Хорошая борьба < /span> <
/a> <
/div>
/* Стрелка Назад*/
.Slider_btn_prev__xfwu8 {
left: 0;
}
.Slider_btn__B8Qtp {
position: absolute;
top: 0;
z-index: 9;
width: calc(80px - 16px);
height: 100%;
transition: opacity .2s ease-in-out;
opacity: 0;
cursor: pointer;
pointer-events: none;
background-repeat: no-repeat;
background-position: 50%;
}
.Slider_btn_prev__xfwu8.Slider_btnArrow__Aafu_ {
background-image: url(/src/Components/Assets/Arrows/left.svg);
}
.Slider_btnArrow__Aafu_ {
width: 100%;
height: 100%;
background-repeat: no-repeat;
background-position: 50%;
background-size: 20px;
transition: transform .25s ease;
}
/* Стрелка Вперед*/
.Slider_btn_visible__LJrxs {
opacity: 1;
pointer-events: auto;
}
.Slider_btn_next__xB4sg {
right: 0;
}
.Slider_btn_next__xB4sg.Slider_btnArrow__Aafu_ {
background-image: url(/src/Components/Assets/Arrows/right.svg);
}
Ответы (1 шт):
Автор решения: Павел
→ Ссылка
const images = [
{ url: image1, logo: logo1, title: 'HALO' },
{ url: image2, logo: logo2, title: 'Призраки' },
{ url: image3, logo: logo3, title: 'Хорошая борьба' },
{ url: image4, logo: logo4, title: 'Название 4' },
{ url: image5, logo: logo5, title: 'Название 5' },
{ url: image6, logo: logo6, title: 'Название 6' },
{ url: image7, logo: logo7, title: 'Название 7' },
{ url: image8, logo: logo8, title: 'Название 7' },
{ url: image9, logo: logo9, title: 'Название 7' },
{ url: image10, logo: logo10, title: 'Название 8' },
{ url: image11, logo: logo11, title: 'Название 9' },
{ url: image12, logo: logo12, title: 'Название 10' },
{ url: image13, logo: logo13, title: 'Название 11' },
];
const ShowCase = () => {
const [activeSlide, setActiveSlide] = useState(0);
const handlePrev = () => setActiveSlide(Math.max(activeSlide - 1, 0));
const handleNext = () => setActiveSlide(Math.min(activeSlide + 1, images.length - 4));
return (
<div className='Showcase_item__ajKek'>
<div>
<div className='common_line__9RJLR common_line_type_promo-editors___GaUP PromoVideoline_line__iqVKv PromoVideoline_line_type_promo-editors__0Mf2V'
data-gtm-vis-first-on-screen11350452_351="939" data-gtm-vis-total-visible-time11350452_351="100" data-gtm-vis-has-fired11350452_351="1" >
<div className='Header_header__YhTu_ PromoVideoline_header__v2m27'>
<div className='Header_wrapper__rgWJb'>
<h2 className='Header_title__n1TZ2'>Новое в Flixo</h2>
</div>
</div>
<div className='Slider_slider__RbzAd' style={{'--slideToShow': '5', '--slides-offset': '16px'}}>
<div className='Slider_btn__B8Qtp Slider_btn_prev__xfwu8 PromoVideoline_sliderButton__7NopD Slider_btn_visible__LJrxs' onClick={handlePrev} style={{backgroundImage: `url(${left})`}}>
<div className='Slider_btnArrow__Aafu_'></div>
</div>
<div className='Slider_btn__B8Qtp Slider_btn_next__xB4sg PromoVideoline_sliderButton__7NopD Slider_btn_visible__LJrxs' onClick={handleNext} style={{backgroundImage: `url(${right})`}}>
<div className='Slider_btnArrow__Aafu_'></div>
</div>
<div className='Slider_container__v97Np PromoVideoline_sliderContainer__RcVni' >
<div className='Slider_wrapper__O8hJs PromoVideoline_sliderWrapper__rq6Hq' style={{transform: 'translateX(0px)'}}>
{images.slice(activeSlide, activeSlide + 13).map((image, index) => (
<div key={index} data-slideindex={activeSlide + index} className={`Slider_slide__prVHT Slider_slide_in_view___jKkg ${activeSlide === index ? 'active' : ''}`} >
<a className='common_card_type_promo-editors__39291 UniversalPromoCard_card__XDJE_' href="#" style={{zIndex: 1000 - index}}>
<div className='UniversalPromoCard_imageWrapper__81un3' style={{color: 'rgb(31, 33, 37)'}}>
<div className='UniversalPromoCard_imageWrapper__UD20K' style={{backgroundImage: `url(${image.url})`, clipPath: 'polygon(0% 5%, 100% 0%, 100% 100%, 0% 100%)'}}>
<div className='UniversalPromoCard_ageRestrictions__wKovT'>18+</div>
<div className='UniversalPromoCard_gradient__Oyt0j UniversalPromoCard_gradient_preset_layered-poster__VCnPW UniversalPromoCard_gradient_with_shadow__bk_Bw UniversalPromoCard_gradient_with_accent__CDZ8Z UniversalPromoCard_gradient_with_cornerShadow__l90XL' ></div>
<img className='UniversalPromoCard_logo__kakl2' src={image.logo} alt="" style={{marginTop: `${[1].includes(activeSlide + index + 1) ? '105%' : [12].includes(activeSlide + index + 1) ? '65%' : [10].includes(activeSlide + index + 1) ? '85%' :[7].includes(activeSlide + index + 1) ? '80%' : [2].includes(activeSlide + index + 1) ? '90%' : '100%'}`, width: '100%', height: 'auto'}}/>
</div>
</div>
<span className='visually-hidden'>{image.title}</span>
</a>
</div>))}