Skip to content

Instantly share code, notes, and snippets.

@zdimaz
Last active December 7, 2018 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zdimaz/d3cb1e3a4a9b207a7c3111ba2930e704 to your computer and use it in GitHub Desktop.
Save zdimaz/d3cb1e3a4a9b207a7c3111ba2930e704 to your computer and use it in GitHub Desktop.
spy title on scroll
// ==========================================================================
// Spy category
// ==========================================================================
if (screen.width <= 720) {
function spyCategory() {
$('.spy_category_item').each( function () {
if ($(window).scrollTop() + $(window).height() > $(this).offset().top && $(window).scrollTop() < $(this).offset().top) {
var title = $(this).data("category-title");
var link = $(this).data("category-link");
if (title == null) {
$('#spy_category').hide();
} else {
$('#spy_category').show();
}
$('#spy_category').find("a").text(title);
$('#spy_category').find("a").attr("href", link);
return;
}
});
}
spyCategory();
$(window).on("scroll resize", function () {
spyCategory();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment