I have a page with multiple bxSlider and, when the user clicks a button, every slider needs to be reloaded with new images.
Everything works fine when I have a single slider, but it stops working with more than one slider.
When the reloadSlider()
method is called I get a "$(...).reloadSlider is not a function"
error.
Since the sliders are dynamically created (I don't know how many of them I'll have on the page), I can't create every single slider on like this:
var slider1 = $('#slider1').bxSlider();
var slider2 = $('#slider2').bxSlider();
...
But I need to create them all at once with:
$('.slider').bxSlider();
But when I try to call $('.slider').reloadSlider()
, I get the error above.
Can someone help me? Thank you.
I have a page with multiple bxSlider and, when the user clicks a button, every slider needs to be reloaded with new images.
Everything works fine when I have a single slider, but it stops working with more than one slider.
When the reloadSlider()
method is called I get a "$(...).reloadSlider is not a function"
error.
Since the sliders are dynamically created (I don't know how many of them I'll have on the page), I can't create every single slider on like this:
var slider1 = $('#slider1').bxSlider();
var slider2 = $('#slider2').bxSlider();
...
But I need to create them all at once with:
$('.slider').bxSlider();
But when I try to call $('.slider').reloadSlider()
, I get the error above.
Can someone help me? Thank you.
Share Improve this question edited Apr 23, 2015 at 14:07 cr0ss 8775 silver badges20 bronze badges asked Feb 25, 2015 at 17:33 CuttlefishCuttlefish 1871 gold badge3 silver badges10 bronze badges3 Answers
Reset to default 3I had the same issue and i e up with this. You can initially load all sliders in array like:
var sliders = [];
$('.sliders').each(function(i,item){
var slider;
slider.$(this).bxSlider();
sliders[i] = slider;
});
Then, you can loop through and reload each
$(sliders).each(function(){
this.reloadSlider();
});
var sliders = $('.slider').map(function() {
return $(this).bxSlider();
});
sliders.each(function() {
this.reloadSlider();
});
I ran into a similar problem.
The slider was initialized and attached to an object:
someObj.slider = $('.slider').bxSlider({...})
.
Later from a different method calling
someObj.slider.reloadSlider()
didn't work but someObj.slider.data('bxSlider').reloadSlider()
did.
Hope this helps..
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745334686a4623048.html
评论列表(0条)