I see you can set the interval but I want to control how fast the items slide?
// Sets interval...what is transition slide speed?
$('#mainCarousel').carousel({
interval: 3000
});
Approach 1: We can control the animation by using the data interval attribute of each carousel item. The given example is the best example for understanding this concept. The Data-interval attribute is used to set the interval time between two carousel item by default its value is 3000 milliseconds.
You can simply use the data-interval attribute of the carousel class. It's default value is set to data-interval="3000" i.e 3seconds. All you need to do is set it to your desired requirements.
The transition duration of . carousel-item can be changed with the $carousel-transition-duration Sass variable before compiling or custom styles if you're using the compiled CSS. If multiple transitions are applied, make sure the transform transition is defined first (eg. transition: transform 2s ease, opacity .
The speed cannot be controlled by the API. Though you can modify CSS that is in charge of that.
In the carousel.less
file find
.item {
display: none;
position: relative;
.transition(.6s ease-in-out left);
}
and change .6s
to whatever you want.
In case you do not use .less, find in the bootstrap.css
file:
.carousel-inner > .item {
position: relative;
display: none;
-webkit-transition: 0.6s ease-in-out left;
-moz-transition: 0.6s ease-in-out left;
-o-transition: 0.6s ease-in-out left;
transition: 0.6s ease-in-out left;
}
and change 0.6s
to the time you want. You also might want to edit time in the function call below:
.emulateTransitionEnd(2000)
at bootstrap.js
in function Carousel.prototype.slide
. That synchronize transition and prevent slide to disapear before transition ends.
EDIT 7/8/2014
As @YellowShark pointed out the edits in JS are not needed anymore. Only apply css changes.
EDIT 20/8/2015 Now, after you edit your css file, you just need to edit CAROUSEL.TRANSITION_DURATION (in bootstrap.js) or c.TRANSITION_DURATION (if you use bootstrap.min.js) and to change the value inside it (600 for default). The final value must be the same that you put in your css file( for example 10s in css = 10000 in .js)
EDIT 16/01/2018 For Bootstrap 4, to change the transition time to e.g., 2 seconds, add
$(document).ready(function() {
jQuery.fn.carousel.Constructor.TRANSITION_DURATION = 2000 // 2 seconds
});
to your site's JS file, and
.carousel-inner .carousel-item {
transition: -webkit-transform 2s ease;
transition: transform 2s ease;
transition: transform 2s ease, -webkit-transform 2s ease;
}
to your site's CSS file.
Just write data-interval
in the div
containing the carousel:
<div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="500">
Example taken from w3schools.
You need to set interval in the main DIV as data-interval tag. The it will work fine and you can give different time to different slides.
<div class="carousel" data-interval="5000">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With