Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alessandroalessio/c57171db5c53354f85b367ad7c5f00b5 to your computer and use it in GitHub Desktop.
Save alessandroalessio/c57171db5c53354f85b367ad7c5f00b5 to your computer and use it in GitHub Desktop.
owlCarousel 2 managed by Data Attribute
// Carousel
if ( jQuery('.owl-carousel').length ) {
jQuery.each( jQuery('.owl-carousel'), function(){
var owlItems = jQuery('.owl-carousel').data('items') ? jQuery('.owl-carousel').data('items') : 3;
owlOptions = [];
if ( typeof jQuery(".owl-carousel").data('items') !== 'undefined' ) owlOptions['items'] = jQuery(".owl-carousel").data('items');
if ( typeof jQuery(".owl-carousel").data('loop') !== 'undefined' ) owlOptions['loop'] = jQuery(".owl-carousel").data('loop');
if ( typeof jQuery(".owl-carousel").data('margin') !== 'undefined' ) owlOptions['margin'] = jQuery(".owl-carousel").data('margin');
if ( typeof jQuery(".owl-carousel").data('nav') !== 'undefined' ) owlOptions['nav'] = jQuery(".owl-carousel").data('nav');
if ( typeof jQuery(".owl-carousel").data('dots') !== 'undefined' ) owlOptions['dots'] = jQuery(".owl-carousel").data('dots');
if ( typeof jQuery(".owl-carousel").data('autoplay') !== 'undefined' ) owlOptions['autoplay'] = jQuery(".owl-carousel").data('autoplay');
if ( typeof jQuery(".owl-carousel").data('autoplay-timeout') !== 'undefined' ) owlOptions['owlAutoplayTimeout'] = jQuery(".owl-carousel").data('autoplay-timeout');
var $carousel = jQuery(this);
$carousel.owlCarousel(owlOptions);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment