Last active
August 29, 2015 14:10
-
-
Save teledirigido/9610894e7a758efb8075 to your computer and use it in GitHub Desktop.
Check when divs have reached the top of the window
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 custom_menu = { | |
handle_colors: function(){ | |
// by default this works with $(window).on('load resize scroll') | |
$('.scroller').on('load resize scroll', function(){ | |
var index_item = custom_menu._get_index(), | |
class_item = $('.wrapper-milkguard:eq('+index_item+')').data('menu-color') | |
$('#trigger').attr('rel', class_item ); | |
}); | |
}, | |
_get_index: function(){ | |
var layout_list = $('.wrapper-milkguard'), // item to check | |
scroll_top = $('.scroller').scrollTop(), // by default this works with $('body') | |
special_offset = 50; // if we want to customize our offset top when we check the div DEFAULT: 0 | |
var offset_list; | |
// we go through every item list | |
for( var i = 0 ; i <= layout_list.length ; i++ ){ | |
if( $(layout_list[i]).index() > 0 && | |
$(layout_list[i]).offset().top < special_offset && | |
$(layout_list[i-1]).length ){ | |
offset_list = $(layout_list[i]).offset().top > $(layout_list[i-1]).offset().top ? $(layout_list[i]).index() : 0; | |
} | |
} | |
// If offset it's not defined | |
if( typeof offset_list === 'undefined' ) offset_list = 0; | |
return offset_list; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment