-
Notifications
You must be signed in to change notification settings - Fork 0
/
deck.panorama.js
executable file
·89 lines (81 loc) · 2.44 KB
/
deck.panorama.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
/*!
Deck JS - deck.navigation
Copyright (c) 2011-2014 Caleb Troughton
Dual licensed under the MIT license.
https://github.com/imakewebthings/deck.js/blob/master/MIT-license.txt
*/
/*
This module creates a panorama-background, known from the Android System.
*/
(function($, undefined) {
var $document = $(document);
var moveBackground = function(forward, tiles) {
var px = $.deck('getOptions').backgroundMovementWidth * tiles;
if (forward)
px *= -1;
$('.bg').finish();
$('.bg').each(function(){
$(this).animate({
left: "-="+px
}, 500);
});
};
var findBackgroundIndex = function(realIdx) {
var slideCount= $.deck('getSlides').length;
var slides = $.deck('getSlides');
var options = $.deck('getOptions');
var slidecnt = 0;
for (i = 0; i < realIdx; i++) {
var slide = slides[i];
var isSub = slide.closest('.' + options.classes.childCurrent).length;
if (!isSub)
slidecnt++;
}
return slidecnt;
};
var prepareBackgroundMove = function() {
var slideCount= $.deck('getSlides').length;
var slides = $.deck('getSlides');
var options = $.deck('getOptions');
var slidecnt = 0;
for (i = 0; i < slideCount; i++) {
var slide = slides[i];
var isSub = slide.closest('.' + options.classes.childCurrent).length;
if (!isSub)
slidecnt++;
}
var slideMoveWidth = $(window).width(); /* for the 200% */
options.backgroundMovementWidth = slideMoveWidth / slidecnt;
};
var moveBackgroundRes = function(currentIndex, idx) {
var slides = $.deck('getSlides');
var options = $.deck('getOptions');
if (idx > currentIndex && currentIndex > 1) {
var slide = slides[idx];
var isSub = slide.closest('.' + options.classes.childCurrent).length;
if (!isSub) {
moveBackground(false, idx-currentIndex);
}
} else if (idx < currentIndex) {
var slide = slides[idx];
if (slide != null) {
var isSub = slide.closest('.' + options.classes.childCurrent).length;
var slide2 = slides[currentIndex];
var isSub2 = slide2.closest('.' + options.classes.childCurrent).length;
if (!isSub && !isSub2) {
moveBackground(true, currentIndex-idx);
}
} else {
moveBackground(true, currentIndex-idx);
}
} else if (currentIndex == 0 && idx != 0) {
moveBackground(false, idx);
}
};
$document.bind('deck.init', function(opts) {
prepareBackgroundMove();
});
$document.bind('deck.change', function(event, currentIndex, index) {
moveBackgroundRes(currentIndex, index);
});
})(jQuery);