forked from jacobjinkelly/Glenforest-STEM-Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.js
116 lines (112 loc) · 4.48 KB
/
core.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
if (window.jQuery){
//highlights current nav element based on which anchor was just passed
$(window).scroll(function(){
var aboutAnchor=$("#ABOUT").get();
var aboutAnchorPosition=$(aboutAnchor).offset().top;
var aboutNav=$("#About").get();
var conferenceAnchor=$("#CONFERENCE").get();
var conferenceAnchorPosition=$(conferenceAnchor).offset().top;
var conferenceNav=$("#Conference").get();
var sponsorAnchor=$("#SPONSOR").get();
var sponsorAnchorPosition=$(sponsorAnchor).offset().top;
var sponsorNav=$("#Sponsor").get();
var contactAnchor=$("#CONTACT").get();
var contactAnchorPosition=$(contactAnchor).offset().top;
var contactNav=$("#Contact").get();
var eventsNav=$("#Events").get();
var announcementsNav=$("#Announcements").get();
var top_window=$(window).scrollTop()+$(window).height()*0.08; //approximate proportion of anchor position and nav height
if (top_window>aboutAnchorPosition){
$(aboutNav).addClass('current');
$(conferenceNav).removeClass('current');
$(sponsorNav).removeClass('current');
$(contactNav).removeClass('current');
$(eventsNav).removeClass('current');
$(announcementsNav).removeClass('current');
}
else $(aboutNav).removeClass('current');
if (top_window>conferenceAnchorPosition){
$(aboutNav).removeClass('current');
$(conferenceNav).addClass('current');
$(sponsorNav).removeClass('current');
$(contactNav).removeClass('current');
$(eventsNav).removeClass('current');
$(announcementsNav).removeClass('current');
}
if (top_window>sponsorAnchorPosition){
$(aboutNav).removeClass('current');
$(conferenceNav).removeClass('current');
$(sponsorNav).addClass('current');
$(contactNav).removeClass('current');
$(eventsNav).removeClass('current');
$(announcementsNav).removeClass('current');
}
if (top_window>contactAnchorPosition){
$(aboutNav).removeClass('current');
$(conferenceNav).removeClass('current');
$(sponsorNav).removeClass('current');
$(contactNav).addClass('current');
$(eventsNav).removeClass('current');
$(announcementsNav).removeClass('current');
}
if (location.pathname.split(/[\\\/]+/).pop()=="events.html"){
$(aboutNav).removeClass('current');
$(conferenceNav).removeClass('current');
$(sponsorNav).removeClass('current');
$(contactNav).removeClass('current');
$(eventsNav).addClass('current');
$(announcementsNav).removeClass('current');
}
if (location.pathname.split(/[\\\/]+/).pop()=="announcements.html"){
$(aboutNav).removeClass('current');
$(conferenceNav).removeClass('current');
$(sponsorNav).removeClass('current');
$(contactNav).removeClass('current');
$(eventsNav).removeClass('current');
$(announcementsNav).addClass('current');
}
});
//changes appearance of nav by adding class 'scrolled'
$(window).scroll(function(){
var top_object=$("#title").offset().top;
var top_window=$(window).scrollTop()+$(window).height()*0.05; //approximate proportion of nav to screen
if (top_window>top_object) $('#nav').addClass('scrolled');
else $('#nav').removeClass('scrolled');
});
//fades in pics of core5 once scrolled
$(window).scroll(function(){
var n=parseInt($('.fadeIn').css('top'),10); //accounts for different between exec and fadeIn top positioning
$('.exec').each(function(i){
var top_object=$(this).offset().top-(parseInt($(this).css('top'),10)-n);
var bottom_window=$(window).scrollTop()+$(window).height();
if (bottom_window>top_object){
$(this).addClass('popIn');
}
});
});
//fades in elements as scroll down
$(window).scroll(function(){
$('.fadeIn').each(function(i){
var top_object=$(this).offset().top;
var top_window=$(window).scrollTop()+$(window).height();
if (top_window>top_object){
$(this).addClass('popIn');
}
});
});
//animated scroll to anchors on page
$(document).ready(function(){
$('a[href*=#]:not([href=#])').click(function(){
if (location.pathname.replace(/^\//,'')==this.pathname.replace(/^\//,'')&&location.hostname==this.hostname){
var target=$(this.hash);
target=target.length?target:$('[name='+this.hash.slice(1)+']');
if (target.length){
$('html,body').stop().animate({
scrollTop:target.offset().top
},500,'swing');
return false;
}
}
});
});
}