This repository has been archived by the owner on Mar 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple-owl-slider.js
74 lines (72 loc) · 2.8 KB
/
simple-owl-slider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* Simple Owl Carousel Slider
*/
$(function() {
$('.owl-slider').each(function() {
let item = ( $(this).data('item') != undefined ) ? parseInt($(this).data('item')) : 1;
let itemSm = ( $(this).data('item-sm') != undefined ) ? parseInt($(this).data('item-sm')) : item;
let itemMd = ( $(this).data('item-md') != undefined ) ? parseInt($(this).data('item-md')) : itemSm;
let itemLg = ( $(this).data('item-lg') != undefined ) ? parseInt($(this).data('item-lg')) : itemMd;
let itemXl = ( $(this).data('item-xl') != undefined ) ? parseInt($(this).data('item-xl')) : itemLg;
let margin = ( $(this).data('margin') != undefined ) ? parseInt($(this).data('margin')) : 0;
let play = ( $(this).data('autoplay') != undefined ) ? $(this).data('autoplay') : true;
let looping = ( $(this).data('loop') != undefined ) ? $(this).data('loop') : true;
let timeout = $(this).data('timeout');
let animation = $(this).data('animation');
let drag = ( $(this).data('drag') != undefined ) ? $(this).data('drag') : true;
let hoverPause = ( $(this).data('hover-pause') != undefined ) ? $(this).data('hover-pause') : false;
// Disable loop if actual item count is less than data-item
let loopingSm = looping;
let loopingMd = looping;
let loopingLg = looping;
let loopingXl = looping;
if ( $(this).data('smart-loop') ) {
let itemCount = $(this).find('.item').length;
if ( itemCount <= itemSm ) {
loopingSm = false;
itemSm = itemCount;
}
if ( itemCount <= itemMd ) {
loopingMd = false;
itemMd = itemCount;
}
if ( itemCount <= itemLg ) {
loopingLg = false;
itemLg = itemCount;
}
if ( itemCount <= itemXl ) {
loopingXl = false;
itemXl = itemCount;
}
}
$(this).addClass('owl-carousel');
$(this).owlCarousel({
dots: false,
margin: margin,
// animateIn: animation,
animateOut: animation,
autoplay: play,
autoplayTimeout: timeout,
mouseDrag: drag,
autoplayHoverPause: hoverPause,
responsive: {
0: {
items: itemSm,
loop: loopingSm
},
768: {
items: itemMd,
loop: loopingMd
},
992: {
items: itemLg,
loop: loopingLg
},
1200: {
items: itemXl,
loop: loopingXl
}
}
});
})
})