-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
73 lines (60 loc) · 2.32 KB
/
main.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
/*$(function(){
var counter = 0, // to keep track of current slide
$items = document.querySelectorAll('div.show'), // a collection of all of the slides, caching for performance
numItems = $items.length; // total number of slides
// this function is what cycles the slides, showing the next or previous slide and hiding all the others
var showCurrent = function(){
var itemToShow = Math.abs(counter%numItems);// uses remainder (aka modulo) operator to get the actual index of the element to show
// remove .show from whichever element currently has it
// http://stackoverflow.com/a/16053538/2006057
[].forEach.call( $items, function(el){
el.classList.remove('show');
});
// add .show to the one item that's supposed to have it
$items[itemToShow].classList.add('show');
};
// add click events to prev & next buttons
document.querySelector('.next').addEventListener('click', function() {
counter++;
showCurrent();
}, false);
document.querySelector('.prev').addEventListener('click', function() {
counter--;
showCurrent();
}, false);
})();
*/
$(function(){
var counter = 0, // to keep track of current slide
$items = $('.slideshow figure'), // a collection of all of the slides, caching for performance
numItems = $items.length; // total number of slides
// this function is what cycles the slides, showing the next or previous slide and hiding all the others
var showCurrent = function(){
var itemToShow = Math.abs(counter%numItems);// uses remainder (aka modulo) operator to get the actual index of the element to show
console.log(itemToShow);
$items.removeClass('show'); // remove .show from whichever element currently has it
$items.eq(itemToShow).addClass('show');
};
// add click events to prev & next buttons
$('.next').on('click', function(){
counter++;
showCurrent();
});
$('.prev').on('click', function(){
counter--;
showCurrent();
});
// if touch events are supported then add swipe interactions using TouchSwipe https://github.com/mattbryson/TouchSwipe-Jquery-Plugin
// if('ontouchstart' in window){
// $('.slideshow').swipe({
// swipeLeft:function() {
// counter++;
// showCurrent();
// },
// swipeRight:function() {
// counter--;
// showCurrent();
// }
// });
// }
});