Created
October 1, 2014 12:17
-
-
Save marcelo2605/4a3812cd883d2e8f04e9 to your computer and use it in GitHub Desktop.
Detectar o id de uma div durante scroll horizontal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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