Created
November 1, 2011 16:34
-
-
Save craigmdennis/1331038 to your computer and use it in GitHub Desktop.
Dynamically generate multiple BX Sliders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use this if you need to have multiple slideshows on one page but are unsure how many will be needed. | |
Markup: | |
<div class="gallery"> | |
<img src="http://placehold.it/300" /> | |
<img src="http://placehold.it/300" /> | |
<img src="http://placehold.it/300" /> | |
</div> | |
<div class="gallery"> | |
<img src="http://placehold.it/300" /> | |
<img src="http://placehold.it/300" /> | |
<img src="http://placehold.it/300" /> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function () { | |
var bxSliderInstances = {}; | |
// Use a class rather than an ID | |
var $slider = $('.mini-slider'); | |
// For each result | |
$slider.each(function (index, element) { | |
// If there is more than 1 image | |
if ($(element).find('img').length > 1) { | |
// Initialise a slider using the current index value | |
bxSliderInstances['slider' + index] = $slider.eq(index).bxSlider({ | |
auto: false, | |
pager: false, | |
prevText: '←', | |
nextText: '→', | |
duration: 500 | |
}); | |
} | |
}); | |
$('#button').click(function (e) { | |
e.preventDefault(); | |
// Use public functions | |
bxSliderInstances.slider1.goToNextSlide(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bit late but for anyone that is looking for a solution to this: