{Theme} comes with Owl Carousel component – plugin documentation available here
How to use it
To enable plugin on your page include the following HTML code to your page:
1 |
<script src="assets/owl-carousel/owl.carousel.js"></script> |
Set up your HTML
You don’t need any special markup. All you need is to wrap your divs(owl works with any type element) inside the container element
. Class “owl-carousel” is mandatory to apply proper styles that come from owl.carousel.css file.
1 2 3 4 5 6 7 8 9 10 |
<div id="owl-example" class="owl-carousel"> <div> Your Content </div> <div> Your Content </div> <div> Your Content </div> <div> Your Content </div> <div> Your Content </div> <div> Your Content </div> <div> Your Content </div> ... </div> |
Now call the Owl initializer function and your carousel is ready.
1 2 3 4 5 |
$(document).ready(function() { $("#owl-example").owlCarousel(); }); |
Customizing
-
Options
All of the options below are available to customize Owl Carousel
12345678910111213141516171819202122232425262728293031323334353637383940Variable Default Type Descriptionitems 5 int This variable allows you to set the maximum amount of items displayed at a time with the widest browser widthitemsDesktop [1199,4] array This allows you to preset the number of slides visible with a particular browser width. The format is [x,y] whereby x=browser width and y=number of slides displayed. For example [1199,4] means that if(window<=1199){ show 4 slides per page} Alternatively use itemsDesktop: false to override these settings. Check my Custom DemoitemsDesktopSmall [979,3] array As above.itemsTablet [768,2] array As above.itemsTabletSmall false array As above. Default value is disabled.itemsMobile [479,1] array As aboveitemsCustom false array This allow you to add custom variations of items depending from the width If this option is set, itemsDeskop, itemsDesktopSmall, itemsTablet, itemsMobile etc. are disabled For better preview, order the arrays by screen size, but it's not mandatory Don't forget to include the lowest available screen size, otherwise it will take the default one for screens lower than lowest available.Example:[[0, 2], [400, 4], [700, 6], [1000, 8], [1200, 10], [1600, 16]]For more information about structure of the internal arrays see itemsDesktop. Check my Custom DemosingleItem false boolean Display only one item. See demoitemsScaleUp false boolean Option to not stretch items when it is less than the supplied items. See demoslideSpeed 200 int Slide speed in millisecondspaginationSpeed 800 int Pagination speed in millisecondsrewindSpeed 1000 int Rewind speed in millisecondsautoPlay false int/boolean Change to any integrer for example autoPlay : 5000 to play every 5 seconds. If you set autoPlay: true default speed will be 5 seconds.stopOnHover false boolean Stop autoplay on mouse hovernavigation false boolean Display "next" and "prev" buttons.navigationText ["prev","next"] array You can cusomize your own text for navigation. To get empty buttons use navigationText : false. Also HTML can be used hererewindNav true boolean Slide to first item. Use rewindSpeed to change animation speed.scrollPerPage false boolean Scroll per page not per item. This affect next/prev buttons and mouse/touch dragging.pagination true boolean Show pagination.paginationNumbers false boolean Show numbers inside pagination buttonsresponsive true boolean You can use Owl Carousel on desktop-only websites too! Just change that to "false" to disable resposive capabilitiesresponsiveRefreshRate 200 int Check window width changes every 200ms for responsive actionsresponsiveBaseWidth window jQuery selector Owl Carousel check window for browser width changes. You can use any other jQuery element to check width changes for example ".owl-demo". Owl will change only if ".owl-demo" get new width.baseClass "owl-carousel" string Automaticly added class for base CSS styles. Best not to change it if you don't need to.theme "owl-theme" string Default Owl CSS styles for navigation and buttons. Change it to match your own themelazyLoad false boolean Delays loading of images. Images outside of viewport won't be loaded before user scrolls to them. Great for mobile devices to speed up page loadings. IMG need special markup class="lazyOwl" and data-src="your img path". See example.lazyFollow true boolean When pagination used, it skips loading the images from pages that got skipped. It only loads the images that get displayed in viewport. If set to false, all images get loaded when pagination used. It is a sub setting of the lazy load function.lazyEffect "fade" boolean / string Default is fadeIn on 400ms speed. Use false to remove that effect.autoHeight false boolean Add height to owl-wrapper-outer so you can use diffrent heights on slides. Use it only for one item per page setting.jsonPath false string Allows you to load directly from a jSon file. The JSON structure you use needs to match the owl JSON structure used here. To use custom JSON structure see jsonSuccess option.jsonSuccess false function Success callback for $.getJSON build in into carousel. See demo with custom JSON structure here.dragBeforeAnimFinish true boolean Ignore whether a transition is done or not (only dragging).mouseDrag true boolean Turn off/on mouse events.touchDrag true boolean Turn off/on touch events.addClassActive false boolean Add "active" classes on visible items. Works with any numbers of items on screen.transitionStyle false string Add CSS3 transition style. Works only with one item on screen. See Demo -
Callbacks
12345678910Variable Default Type DescriptionbeforeUpdate false function Before responsive update callbackafterUpdate false function After responsive update callbackbeforeInit false function Before initialization callbackafterInit false function After initialization callbackbeforeMove false function Before move callbackafterMove false function After move callbackafterAction false function After startup, move and update callbackstartDragging false function Call this function while dragging.afterLazyLoad false function Call this function after lazyLoad. -
Defaults
Carousel default settings
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576$("#owl-example").owlCarousel({// Most important owl featuresitems : 5,itemsCustom : false,itemsDesktop : [1199,4],itemsDesktopSmall : [980,3],itemsTablet: [768,2],itemsTabletSmall: false,itemsMobile : [479,1],singleItem : false,itemsScaleUp : false,//Basic SpeedsslideSpeed : 200,paginationSpeed : 800,rewindSpeed : 1000,//AutoplayautoPlay : false,stopOnHover : false,// Navigationnavigation : false,navigationText : ["prev","next"],rewindNav : true,scrollPerPage : false,//Paginationpagination : true,paginationNumbers: false,// Responsiveresponsive: true,responsiveRefreshRate : 200,responsiveBaseWidth: window,// CSS StylesbaseClass : "owl-carousel",theme : "owl-theme",//Lazy loadlazyLoad : false,lazyFollow : true,lazyEffect : "fade",//Auto heightautoHeight : false,//JSONjsonPath : false,jsonSuccess : false,//Mouse EventsdragBeforeAnimFinish : true,mouseDrag : true,touchDrag : true,//TransitionstransitionStyle : false,// OtheraddClassActive : false,//CallbacksbeforeUpdate : false,afterUpdate : false,beforeInit: false,afterInit: false,beforeMove: false,afterMove: false,afterAction: false,startDragging : falseafterLazyLoad : false}) -
Custom Events
Owl Carousel handles a few basic events. Mainly use them for custom navigation.
123456"owl.prev" //Go to previous"owl.next" //Go to next"owl.play" //Autoplay, also this event accept autoPlay speed as second parameter"owl.stop" //Stop"owl.goTo" //goTo provided item"owl.jumpTo" //jumpTo provided item. Without slide animation. -
Owl Data methods
To use Owl Carousel $.data use delegate function.
123456789101112131415161718192021//Initialize Plugin$(".owl-carousel").owlCarousel()//get carousel instance data and store it in variable owlvar owl = $(".owl-carousel").data('owlCarousel');//Public methodsowl.next() // Go to next slideowl.prev() // Go to previous slideowl.goTo(x) // Go to x slideowl.jumpTo(x) // Go to x slide without slide animation//Auto Playowl.play() // Autoplayowl.stop() // Autoplay Stop//Manipulation methods. See demo.owl.addItem(htmlString [,targetPosition])owl.removeItem(targetPosition)owl.destroy()owl.reinit(newOptions)