-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfullpagesliderV2.js
92 lines (82 loc) · 2.76 KB
/
fullpagesliderV2.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
(function($){
$.fn.extend({
fullPageSlider: function(opts){
var defaults = {
nav: true,
interval: 8000,
rarrow: $("#right-arrow"),
larrow: $("#left-arrow")
}
var opts = $.extend(defaults, opts);
//var interval = opts.interval;
var currPanel = 0;
var o = opts;
var obj = $(this);
var panels = obj.children(".slide-panel");
var interval = o.interval;
function slidePanel( newPanel, direction, nav ) {
// define the offset of the slider obj, vis a vis the document
var offsetLeft = obj.offset().left;
// offset required to hide the content off to the left / right
var hideLeft = -1 * ( offsetLeft + obj.width() );
var hideRight = $(window).width() - offsetLeft;
// change the current / next positions based on the direction of the animation
if ( direction == 'left' ) {
currPos = hideLeft;
nextPos = hideRight;
}
else {
currPos = hideRight;
nextPos = hideLeft;
}
// slide out the current panel, then remove the active class
obj.children('.slide-panel.active').animate({
left: currPos,
opacity: 0
}, 500, function() {
$(this).removeClass('active');
});
// slide in the next panel after adding the active class
$( panels[newPanel] ).css('left', nextPos).addClass('active').animate({
left: 0,
opacity: 1
}, 500 );
};
if(o.nav == true){
var $navWrap = $('<div id="full-slider-nav"></div>').appendTo( obj );
var $navLeft = $('<div id="full-slider-nav-left"></div>').appendTo( $navWrap );
var $navRight = $('<div id="full-slider-nav-right"></div>').appendTo( $navWrap );
}else{
var $navWrap = $('#full-slider-nav');
var $navLeft = $('#full-slider-nav-left');
var $navRight = $('#full-slider-nav-right');
}
$navLeft.click(function() {
currPanel--;
clearInterval(interval);
// check if the new panel value is too small
if ( currPanel < 0 ) currPanel = panels.length - 1;
slidePanel(currPanel, 'right', false);
interval = setInterval(function() {
currPanel++;
// check if the new panel value is too big
if ( currPanel >= panels.length ) currPanel = 0;
slidePanel(currPanel, 'left', false);
}, o.interval);
});
$navRight.click(function() {
currPanel++;
clearInterval(interval);
// check if the new panel value is too big
if ( currPanel >= panels.length ) currPanel = 0;
slidePanel(currPanel, 'left', false);
interval = setInterval(function() {
currPanel++;
// check if the new panel value is too big
if ( currPanel >= panels.length ) currPanel = 0;
slidePanel(currPanel, 'left', false);
}, o.interval);
});
}
});
})(jQuery);