I'm getting the following error in the console:
Uncaught TypeError: Can not read property 'top' of undefined
He is saying that the error occurs on the following line:
alturaproximo = $(this).next().offset().top;
Follow the code:
$('.lego').each(function() {
var alturadesse = $(this).offset().top,
alturaproximo = $(this).next().offset().top;
console.log(alturadesse);
var zindex = 5;
if ( alturadesse == alturaproximo ) {
$(this).css({'z-index': zindex});
} if ( alturadesse > alturaproximo ) {
zindex + 1;
$(this).css({'z-index': zindex});
}
});
I think he can not get the height offset().top
because of next()
.
Would anyone know what I need to do to compare the top distances of an element and the next element equal to it?