I'm just learning javascript so please bear with me here. I'm trying to initiate two carousels in bootstrap using the same control.
The way it's setup right now, href tags containing the carousel's ID is controlling each carousel. Anyone have advice on how to link both together using the same control with minimal modifications?
Here's the HTML:
<div id="asHero">
<div id="walkThrough" class="carousel slide">
<!-- Carousel items -->
<div class="carousel-inner">
<div class="active item">
<div class="span5">
<h1>Discover</h1>
<p class="heroDesc">Explore the active side of the world around you.</p>
</div>
<div class="span6">
<img src="img/landing/icontest.png" />
</div>
</div>
<div class="item">
<div class="span5">
<h1>Track</h1>
<p class="heroDesc">Keep tabs on frequency and personal bests.</p>
</div>
<div class="span6">
<img src="img/landing/icontest2.png" />
</div>
</div>
<div class="item">
<div class="span5">
<h1>Conquer</h1>
<p class="heroDesc">Earn points and awards for everything you do in your active life.</p>
</div>
<div class="span6">
<img src="img/landing/icontest3.png" />
</div>
</div>
</div>
<!-- Carousel nav -->
<a class="carousel-control right visible-desktop" href="#walkThrough" data-slide="next">›</a>
</div>
</div> <!-- /asHero -->
<div id="asPhone">
<div id="walkThrough-2" class="carousel slide">
<!-- Carousel items -->
<div class="carousel-inner">
<div class="active item">
<div class="span5">
<h1>Discover</h1>
<p class="heroDesc">Explore the active side of the world around you.</p>
</div>
<div class="span6">
<img src="img/landing/icontest.png" />
</div>
</div>
<div class="item">
<div class="span5">
<h1>Track</h1>
<p class="heroDesc">Keep tabs on frequency and personal bests.</p>
</div>
<div class="span6">
<img src="img/landing/icontest2.png" />
</div>
</div>
<div class="item">
<div class="span5">
<h1>Conquer</h1>
<p class="heroDesc">Earn points and awards for everything you do in your active life.</p>
</div>
<div class="span6">
<img src="img/landing/icontest3.png" />
</div>
</div>
</div>
<!-- Carousel nav -->
</div>
</div> <!-- /asPhone -->
Here's a link to the Javascript: Twitter Bootstrap Carousel JS
Any help would be greatly appreciated!
To insert multiple jQuery carousels to the same webpage, you need to create each carousel with a unique ID. In Amazing Carousel, Publish dialog, select the option Publish to Folder, then click Browse to select a folder to save the generated files. You need to set up a unique Carousel ID for each carousel.
The carousel is a slideshow for cycling through a series of content, built with CSS 3D transforms and a bit of JavaScript. It works with a series of images, text, or custom markup. It also includes support for previous/next controls and indicators.
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-bs- , as in data-bs-interval="" . The amount of time to delay between automatically cycling an item.
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.
You can access the carousels using their class carousel
instead of their IDs. This way you can handle multiple carousels with one control.
Add an extra control button to your template
<a href="#" class="btn">Next</a>
And bind a click event to this button to control the carousels
$('.btn').on('click', function(e) {
e.preventDefault()
$('.carousel').carousel('next')
})
The same goes for the prev
control. For more information have a look at the docs.
This is a partial solution, unfortunately. The reason being I can see no way to figure out from the triggered event which direction the thing is going.
$('#walkThrough').carousel({
interval: 5000 // Slide every 5 seconds
});
$('#walkThrough-2').carousel({
interval: false // This one does not slide on its own
});
$('#walkThrough').bind('slide', function() {
$('#walkThrough-2').carousel('next');
});
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