Skip to content

Instantly share code, notes, and snippets.

@marcelo2605
Created October 1, 2014 12:17
Show Gist options
  • Save marcelo2605/4a3812cd883d2e8f04e9 to your computer and use it in GitHub Desktop.
Save marcelo2605/4a3812cd883d2e8f04e9 to your computer and use it in GitHub Desktop.
Detectar o id de uma div durante scroll horizontal
var windowWidth = $( window ).width();
$(window).scroll(function() {
var winLeft = $(this).scrollLeft();
var left = $.grep($('.section'), function(item) {
return $(item).position().left <= winLeft + windowWidth/2;
});
var current = left.slice(-1)[0];
var currentId = $(current).attr('id');
if(!$('a[href$="'+currentId+'"]').hasClass('ativo')){
$('a[href$="'+currentId+'"]').addClass('ativo').parent().siblings().find('a').removeClass('ativo');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment