-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Florian Matter
committed
Jul 20, 2022
1 parent
d233466
commit b07e62a
Showing
1 changed file
with
16 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,33 @@ | ||
function nextSlide() { | ||
var target = $('.slide.active').next('.slide'); | ||
if (target.length == 0) { | ||
target = $('.slide:first'); | ||
function changeSlide(direction="forward") { | ||
var dict = { | ||
"back": "first", | ||
"forward": "last" | ||
} | ||
if (direction=="back") { | ||
var target = $('.slide.active').prev('.slide'); | ||
} else { | ||
var target = $('.slide.active').next('.slide'); | ||
} | ||
$('.slide.active').removeClass('active'); | ||
target.addClass('active'); | ||
$('html, body').scrollTop(target.offset().top - 40); | ||
} | ||
|
||
function previousSlide() { | ||
var target = $('.slide.active').prev('.slide'); | ||
if (target.length == 0) { | ||
target = $('.slide:last'); | ||
target = $('.slide:'+dict[direction]); | ||
} | ||
$('.slide.active').removeClass('active'); | ||
target.addClass('active'); | ||
$('html, body').scrollTop(target.offset().top -40); | ||
$('html, body').scrollTop(target.offset().top - 40); | ||
} | ||
|
||
|
||
window.addEventListener("keydown", (e) => { | ||
if (e.key === "ArrowLeft") { | ||
previousSlide(); | ||
changeSlide("back"); | ||
} else if (e.key === "ArrowRight") { | ||
nextSlide(); | ||
changeSlide(); | ||
} | ||
}) | ||
|
||
$(".next").click(function() { | ||
nextSlide(); | ||
changeSlide(); | ||
}); | ||
|
||
$(".previous").click(function() { | ||
previousSlide(); | ||
}); | ||
changeSlide("back"); | ||
}); |