Owlcarousel2: Add/Remove Items

Created on 21 Jul 2014  路  3Comments  路  Source: OwlCarousel2/OwlCarousel2

Please can someone provide an example of how you can add or remove items.

Thanks,
Lewis

invalid

Most helpful comment

// appends an item to the end
$('.owl-carousel')
  .owlCarousel('add', '<div>foo</div>')
  .owlCarousel('update')
// adds an item before the first item
$('.owl-carousel')
  .trigger('add.owl.carousel', [$('<div>bar</div>'), 0])
  .trigger('refresh.owl.carousel')
// adds multiple items to the end during change
$('.owl-carousel').on('change.owl.carousel', function(e) {
  if (!e.namespace) return
  e.relatedTarget.add($('#foo'))
  e.relatedTarget.add($('#bar'))
  e.relatedTarget.update()
})

Related to #338.

All 3 comments

// appends an item to the end
$('.owl-carousel')
  .owlCarousel('add', '<div>foo</div>')
  .owlCarousel('update')
// adds an item before the first item
$('.owl-carousel')
  .trigger('add.owl.carousel', [$('<div>bar</div>'), 0])
  .trigger('refresh.owl.carousel')
// adds multiple items to the end during change
$('.owl-carousel').on('change.owl.carousel', function(e) {
  if (!e.namespace) return
  e.relatedTarget.add($('#foo'))
  e.relatedTarget.add($('#bar'))
  e.relatedTarget.update()
})

Related to #338.

Great, Thanks

// adds an item before the first item
$('.owl-carousel')
.trigger('add.owl.carousel', [$('

bar
'), 0])
.trigger('refresh.owl.carousel')

It adds front element and replaces the element at index 0

Was this page helpful?
0 / 5 - 0 ratings