I've been trying this for the past 2 days and can't seem to figure out a solution..
I have the prev and next arrows working for navigation (along with arrow keys). But now that I have a timeline, I can't seem to 'jump to' slides using a div-id (correctly)?
So for example, if I wanted to go from section 1 to section 5, I want to be able to click on my section 5 button and it jumps to that slide.
Here is my working example. The slider's timeline appears on slide 2+. For the example, I am only working within the target section.
This is the code I am using to "jump to a slide":
$('.slideshow-timeline a').click(function() {
var target_id = $(this).attr('href');
removeClasses();
$($(".tour-panel")[current]).addClass("fadeOutRight");
setTimeout(function() {
$(target_id).addClass("active-tour fadeInLeft");
}, 50);
setTimeout(function() {
$($(".tour-panel")[current]).removeClass("fadeOutRight");
}, 750);
current = target_id.split('-')[1] || 0;
});
But for some reason, I get 2 specific problems:
Problem 1: I click to go to a slide, then use arrow keys to go back ~ this causes me to jump back 2 slides.
Problem 2: I click to go to a slide, then use arrow keys to go forward ~ this breaks my slider and shows a white screen
I believe the majority of the probelem lies within this line of code:
current = target_id.split('-')[1] || 0;
But I am not 100% sure and need your help, I have prepared a very basic fiddle example here.
Some things I've tried was messing with the split()
variables, swapping out nextElement();
and previousElement();
and I just can not find a solution that works.
All help is very appreciated!
Pastebin to full JS
Pastebin to full CSS
Check out that fiddle:
https://jsfiddle.net/gjyswrr9/19/
Problems were in 3 places:
var previous = parseInt(current, 10) - 1;
var next = parseInt(current) + 1;
(they were strings, not ints).
And
current = target_id.split('-')[1] - 1 || 0;
(you count links starting with 1)
Hope it works as you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With