I think you should apply the selected
classname to the image currently in view.
Upon clicking the "next" button, shift the selected class to the next element like this:
$('.selected').removeClass('selected').next().addClass('selected');
This way you track exactly one element at time, and can show that specific element.
In your getNext
function, x.length === 0
(it's empty) because it's trying to find .popup_img
in this
, and this
is the button that was clicked.
function getNext(){
debugger;
var x = jQuery(this).find('.popup_img');
jQuery('.popup_img').hide();
jQuery('.popup_img').next('.popup_img').show();
console.log(x);
}
EDIT: here are improved next and prev functions:
function getNext() {
var parent = jQuery(this).closest('.gallery-box-file');
var currentImg = parent.find('.popup_img');
var nextParent = parent.next();
if (nextParent.length) {
currentImg.hide();
nextParent.find('.popup_img').show();
}
}
function getPrev() {
var parent = jQuery(this).closest('.gallery-box-file');
var currentImg = parent.find('.popup_img');
var nextParent = parent.prev();
if (nextParent.length) {
currentImg.hide();
nextParent.find('.popup_img').show();
}
}
http://jsfiddle.net/6Q4Va/5/