57 lines
2.2 KiB
JavaScript
57 lines
2.2 KiB
JavaScript
$.fn.floatMenuFunction = function (subMenuItems) {
|
|
var $leftMenu = $(".menuleft");
|
|
if (subMenuItems.length && $leftMenu.length) {
|
|
var list = "";
|
|
for (var i = 0, ln = subMenuItems.length; i < ln; i++) {
|
|
list += "<li><a href=\"#" + $(subMenuItems[i]).attr("id") + "\">" + $(subMenuItems[i]).text() + "</a></li>";
|
|
}
|
|
list = "<ul id=\"floatSubMenu\">" + list + "</ul>";
|
|
$leftMenu.append(list);
|
|
$leftMenu.find("#floatSubMenu").hide();
|
|
$(window).scroll(function () {
|
|
if ($(this).scrollTop() > $("header").height() + $(".undertop").outerHeight() + $leftMenu.outerHeight()) {
|
|
$leftMenu.find("#floatSubMenu").fadeIn();
|
|
} else {
|
|
$leftMenu.find("#floatSubMenu").hide();
|
|
}
|
|
});
|
|
}
|
|
var lastId,
|
|
topMenu = $("nav"),
|
|
topMenuHeight = topMenu.outerHeight()+1,
|
|
menuItems = $("#floatSubMenu").find("a"),
|
|
scrollItems = menuItems.map(function(){
|
|
var item = $($(this).attr("href"));
|
|
if (item.length) { return item; }
|
|
});
|
|
menuItems.click(function(e){
|
|
var href = $(this).attr("href"),
|
|
offsetTop = href === "#" ? 0 : $(href).offset().top;
|
|
$('html, body').stop().animate({
|
|
scrollTop: offsetTop
|
|
}, 500);
|
|
e.preventDefault();
|
|
});
|
|
$(window).scroll(function(){
|
|
// Get container scroll position
|
|
var fromTop = $(this).scrollTop()+topMenuHeight;
|
|
var cur = scrollItems.map(function(){
|
|
if ($(this).offset().top < fromTop)
|
|
return this;
|
|
});
|
|
cur = cur[cur.length-1];
|
|
var id = cur && cur.length ? cur[0].id : "";
|
|
|
|
if (lastId !== id) {
|
|
lastId = id;
|
|
menuItems
|
|
.parent().removeClass("active")
|
|
.end().filter("[href=\"#"+id+"\"]").parent().addClass("active");
|
|
}
|
|
});
|
|
}
|
|
$(document).ready(function () {
|
|
$.fn.floatMenuFunction($(".guidespage .description h2"));
|
|
$.fn.floatMenuFunction($(".mobileguidespages h2"));
|
|
$.fn.floatMenuFunction($(".glossary_list p.gloss_capital"));
|
|
}); |