I'm using Bootstrap Carousel. All I want is that the slider will only slide when a navigation or a pagination is clicked. I've tried removing
$('.carousel').carousel({
interval: 6000
});
It works fine but my problem is once I've already clicked a navigation or pagination, it is now auto sliding. Is it possible to remove the auto sliding function? If so, how?
You can do this 2 ways, via js or html (easist)
$('.carousel').carousel({
interval: false,
});
That will make the auto sliding stop because there no Milliseconds added and will never slider next.
data-interval="false"
and removing data-ride="carousel"
<div id="carouselExampleCaptions" class="carousel slide" data-ride="carousel">
becomes:
<div id="carouselExampleCaptions" class="carousel slide" data-interval="false">
updated based on @webMan's comment
From the official docs :
interval The amount of time to delay between automatically cycling an item. If false , carousel will not automatically cycle.
You can either pass this value with javascript or using a data-interval="false"
attribute.
You just need to add one more attribute to your DIV tag which is
data-interval="false"
no need to touch JS!
在轮播 div 上更改/添加到 data-interval="false"
<div class="carousel slide" data-ride="carousel" data-type="multi" data-interval="false" id="myCarousel">
Please try the following:
<script>
$(document).ready(function() {
$('.carousel').carousel('pause');
});
</script>
在 Bootstrap v5 中使用: data-bs-interval="false"
<div id="carouselExampleCaptions" class="carousel" data-bs-ride="carousel" data-bs-interval="false">
data-interval="false"
Add this to the corresponding div ...
$(document).ready(function() {
$('#media').carousel({
pause: true,
interval: 40000,
});
});
By using the above script, you will be able to move the images automaticaly
$(document).ready(function() {
$('#media').carousel({
pause: true,
interval: false,
});
});
By using the above script, auto-rotation
will be blocked because interval
is false
Omitting the data-bs-ride may work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.