Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const sliderNode = document.createElement('div')
- const SLICE_CLASSES = ['first-slide', 'second-slide']
- const slider = {realIndex: 2}
- const switchSlide = (e) => {
- const currentIndex = slider.realIndex;
- const displacement = e.id === 'next' ? 1 : -1;
- const slidesCnt = SLICE_CLASSES.lemgth - 1;
- const indexSum = currentIndex + displacement;
- slider.realIndex = indexSum < slidesCnt
- ? (indexSum < 0 && slidesCnt) || indexSum
- : 0
- sliderNode.classList.remove(SLICE_CLASSES[currentIndex])
- sliderNode.classList.add(SLICE_CLASSES[slider.realIndex])
- }
- // нужно навесить на кнопки переключения слайдов id=next и id=previous
- // next.addEventListener('click', switchSlide)
- // previous.addEventListener('click', switchSlide)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement