To press any link on a page with a key to navigate - in the example below using next and previous keys (perhaps for portfolio items), hitting the right and left key will take you to the next or previous portoflio item.
// NAVIGATE WITH KEYS
$(document).keydown(function(e) {
switch (e.which) {
case 37: // key arrow left
var href = $('#previous_button').attr('href');
window.location.href = href;
break;
case 39: // key arrow right
var href = $('#next_button').attr('href');
window.location.href = href;
break;
}
e.preventDefault();
});
You just need to give the slider that you want it to work a unique id then put that id into the code - i.e if you give the slider an id of"key-slider" - then the following code should work:
I was also wondering if there’s a way of not targeting each individual slider? If not it’s not that big of deal because it’s my personal website but it would be more convenient when adding new projects.
Ah ok, so you only want it to affect the popup gallery slider that is in focus?
using javascript, you will need to add a class (for example “active-slider”) to the popup gallery when enlarged. and then remove that class when closed. and then use the code below.
If you give the “item-img” the id of the class of the target popup gallery - so the id for the first item img (Film Photography) at the top right id would be gallery-film-photography
and then use this code:
// THIS CODE ADDS THE CLASS TO THE SPECIFIED GALLERY
$(".item-img").on('click', function(){
var galleryId = "." + $(this).attr('id');
$("galleryId").addClass("active-slider");
});
// THIS CODE REMOVES THE CLASS WHEN THE CLOSE BUTTON IS CLICKED
$(".link-block").on('click', function(){
$(this).parent().removeClass("active-slider");
});
I added the following in the ‘Before tag’ section in the page settings:
// THIS CODE ADDS THE CLASS TO THE SPECIFIED GALLERY
$(".item-img").on('click', function(){
var galleryId = "." + $(this).attr('id');
$("galleryId").addClass("active-slider");
});
// THIS CODE REMOVES THE CLASS WHEN THE CLOSE BUTTON IS CLICKED
$(".link-block").on('click', function(){
$(this).parent().removeClass("active-slider");
});
$(document).on('keyup', function(event) {
if (event.which === 37) {
$('.active-slider .w-slider-arrow-left').trigger('tap');
}
else if (event.which === 39) {
$('.active-slider .w-slider-arrow-right').trigger('tap');
}
});
And added ID ‘gallery-film-photography’ to the ‘item img’ div of the Film Photography post/project.
All looks about right - however, if you check the popup div after you click the image - it doesn’t have the active-slider class so there’s an issue there.
you’ll need to do some debugging to find the issue.
This is the code - galleryId should not have been in commas in the addClass line. Let me know if that works.
// THIS CODE ADDS THE CLASS TO THE SPECIFIED GALLERY
$(".item-img").on('click', function(){
galleryId = "." + $(this).attr('id');
$(galleryId).addClass("active-slider");
});
// THIS CODE REMOVES THE CLASS WHEN THE CLOSE BUTTON IS CLICKED
$(".link-block").on('click', function(){
$(this).parent().removeClass("active-slider");
});