最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Bxslider: reload on multiple sliders - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

3 Answers 3

Reset to default 3

I 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..

发布评论

评论列表(0)

  1. 暂无评论