/
main.js
33 lines (27 loc) · 1.14 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var sectionHeight = function() {
var total = $(window).height(),
$section = $('section').css('height','auto');
if ($section.outerHeight(true) < total) {
var margin = $section.outerHeight(true) - $section.height();
$section.height(total - margin - 20);
} else {
$section.css('height','auto');
}
}
$(window).resize(sectionHeight);
$(function() {
$("section h1, section h2, section h3").each(function(){
$("nav ul").append("<li class='tag-" + this.nodeName.toLowerCase() + "'><a href='#" + $(this).text().toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g,'') + "'>" + $(this).text() + "</a></li>");
$(this).attr("id",$(this).text().toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g,''));
$("nav ul li:first-child a").parent().addClass("active");
});
$("nav ul li").on("click", "a", function(event) {
var position = $($(this).attr("href")).offset().top - 190;
$("html, body").animate({scrollTop: position}, 400);
$("nav ul li a").parent().removeClass("active");
$(this).parent().addClass("active");
event.preventDefault();
});
sectionHeight();
$('img').on('load', sectionHeight);
});