How about something like this:
$('.img').on('click', function(){
var $self = $(this),
elements = [],
selfOff = $self.offset().top;
$('.img').each(function(){
if($(this).offset().top == selfOff){
elements.push($(this))
}
})
elements[elements.length-1].addClass('last')
})
Might be a better option, but can't think of another one at the moment. This will select only the last one!
If you need to select the elements between the current and the last:
$('.img').on('click', function(){
var $self = $(this),
elements = [],
selfOff = $self.offset().top;
$('.img').each(function(){
if($(this).offset().top == selfOff){
elements.push($(this))
}
})
$self.nextUntil(elements[elements.length -1]).addClass('last')
})
Or if you like to select all the elements (with the clicked and the last):
$('.img').on('click', function(){
var $self = $(this),
elements = [],
selfOff = $self.offset().top;
$('.img').each(function(){
if($(this).offset().top == selfOff){
elements.push($(this))
}
})
$self.nextUntil(elements[elements.length-1]).add($self).add(elements[elements.length-1]).addClass('last')
})