We switch slides by changing .carousel__contents’s left property. You can transition this property to animate the carousel.
.carousel__contents { /* ... */ transition: left 0.3s ease-out;}
But this transition creates jank. If you want smooth animations, you need to use transform instead of left.
Switching slides with transforms
To switch slides with transforms, you need two things:
- You need to set the correct transform value with JavaScript.
- You need to create a
transitionfor thetransformproperty.
The correct transform value is the same as the correct left value. This applies for all three event listeners.
// remove thiscontents.style.left = '-' + destination// replace with thiscontents.style.transform = 'translateX(-' + destination + ')'To transition the transform property, you set transform in transition.
/* replace with this */.carousel__contents { transform: translateX(0); transition: transform 0.3s ease-out;}
Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson