121

So is there anyway to prevent twitter bootstrap carousel from auto sliding on the page load unless the next or previous button is clicked?

Thanks

Tepken Vannkorn
  • 9,648
  • 14
  • 61
  • 86

11 Answers11

265

Or if you're using Bootstrap 3.0 you can stop the cycling with data-interval="false" for instance

<div id="carousel-example-generic" class="carousel slide" data-interval="false">

Other helpful carousel data attributes are here -> http://getbootstrap.com/javascript/#carousel-usage

Michal Kopec
  • 2,806
  • 2
  • 15
  • 4
  • 4
    This is not 100% the answer to the question because it also stops it from cycling even when a button is clicked. But it was exactly what I was looking for. So thank you anyway! – Tillito Sep 19 '13 at 16:23
  • 3
    `data-interval="false"` also works with **Bootstrap 4** – Ionut Ciuta Apr 01 '18 at 09:59
53

Actually, the problem is now solved. I added the 'pause' argument to the method 'carousel' like below:

$(document).ready(function() {      
   $('.carousel').carousel('pause');
});

Anyway, thanks so much @Yohn for your tips toward this solution.

Tepken Vannkorn
  • 9,648
  • 14
  • 61
  • 86
  • 8
    This will start sliding after prev/next, take a look at http://stackoverflow.com/a/18208327/463065 if that's not what you're looking for. – Trufa Nov 25 '13 at 01:15
  • for a more specific one would be `$(function(){ $("#idName").carousel('pause'); });` – roger Mar 15 '18 at 01:34
43

The problem with carousel automatically sliding after prev/next button press is solved.

$('.carousel').carousel({
    pause: true,
    interval: false
});

GitHub commit 78b927b

Tepken Vannkorn
  • 9,648
  • 14
  • 61
  • 86
Srnux
  • 539
  • 7
  • 5
17

if you're using bootstrap 3 set data-interval="false" on the HTML structure of carousel

example:

<div id="carousel-example-generic" class="carousel slide" data-ride="carousel" data-interval="false">
marciocst
  • 179
  • 1
  • 5
11
  • Use data-interval="false" to stop automatic slide
  • Use data-wrap="false" to stop circular slide
MichaelS
  • 5,941
  • 6
  • 31
  • 46
Anil Ram
  • 111
  • 1
  • 4
10

add this to your coursel div :

data-interval="false"
Bhavin Solanki
  • 4,740
  • 3
  • 26
  • 46
Dylan B
  • 796
  • 8
  • 16
6

Below are the list of parameters for bootstrap carousel. Like Interval, pause, wrap:

enter image description here

For more details refer this link:

http://www.w3schools.com/bootstrap/bootstrap_ref_js_carousel.asp

Hope this will help you :)

Note: This is for further help. I mean how you can customise or change default behaviour once carousel is loaded.

Ij888
  • 50
  • 9
Vikash Pandey
  • 5,407
  • 6
  • 41
  • 42
2

I think maybe you should go to check the official instruction about carousel, for me, i have not found answer above, because of multiple versions of bootstrap, I'm using b4-alpha and i want the autoplay effect stop.

$(document).ready({
    pause:true,
    interval:false
});

this script does not make any effect while mouse leave that page, exactly carousel area. go to official definition and find those :

enter image description here

So you will find why.if carousel page onmouseover event triggered, page will pause, while mouse out of that page, it'll resume again.

So, if you want a page stop forever and rotate manually, you can just set data-interval='false'.

Crabime
  • 644
  • 11
  • 27
1

--Use data-interval="false" to stop automatic slide --Use data-wrap="false" to stop circular slide

...
Anil Kumar Ram
  • 1,211
  • 11
  • 14
1

For Bootstrap 4 simply remove the 'data-ride="carousel"' from the carousel div. This removes auto play at load time.

To enable the auto play again you would still have to use the "play" call in javascript.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Delmontee
  • 1,898
  • 2
  • 26
  • 44
0

Bootstrap 5.2, just remove data-bs-ride

https://getbootstrap.com/docs/5.2/components/carousel/#disable-touch-swiping

Take note that data-bs-interval="false" from Bootstrap 5.0 has been deprecated on Bootstrap 5.2


Bootstrap 5.0, add data-bs-interval="false"

https://getbootstrap.com/docs/5.0/components/carousel/#disable-touch-swiping

cyberfly
  • 5,568
  • 8
  • 50
  • 67