-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (33 loc) · 1.35 KB
/
Copy pathscript.js
File metadata and controls
40 lines (33 loc) · 1.35 KB
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
$(function() {
$("article").hide().first().addClass("slide-active").show() // Show the first slide on launch
$("body").keydown(function(e) {
if (event.which == 32 || event.which == 39) // If left arrow or space bar pressed
nextSlide()
if (event.which == 37) // If right arrow pressed
prevSlide()
})
$("#start_btn").click(firstSlide) // Configure button for changing slide
$("#prev_btn").click(prevSlide)
$("#next_btn").click(nextSlide)
$("#end_btn").click(lastSlide)
})
function nextSlide() { // Hide the current slide and show the next
var oldSlide = $(".slide-active")
if (oldSlide.next().is("article"))
switchSlide(oldSlide, oldSlide.next())
}
function prevSlide() { // Hide the current slide and show the previous one
var oldSlide = $(".slide-active")
if (oldSlide.prev().is("article"))
switchSlide(oldSlide, oldSlide.prev())
}
function firstSlide() { // Hide the current slide and show the first one
switchSlide($(".slide-active"), $("main article").first())
}
function lastSlide() { // Hide the current slide and show the last one
switchSlide($(".slide-active"), $("main article").last())
}
function switchSlide(prev, next) { // Hide the slide "prev" and show the slide "next"
prev.removeClass("slide-active").hide()
next.addClass("slide-active").show()
}