forked from mlvu/mlvu.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mlvu.script.js
86 lines (66 loc) · 2.01 KB
/
mlvu.script.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
$(document).ready(function()
{
// $('.slides nav.menu li a').eq(1).addClass('active');
// - animated slides
$('.slides .anim img').click(function() {
target = $(this)
frames = target.data('images').split(',')
current = target.attr('src');
idx = frames.indexOf(current) + 1;
if (idx >= frames.length)
idx = 0;
target.attr('src', frames[idx]);
if (idx == frames.length -1)
target.parent().addClass('done');
else
target.parent().removeClass('done');
});
});
$(window).on('load', function()
{
// work out the positions of all targets in the menu
let previous = null;
let first = true;
$('.slides nav.menu li a').each(function()
{
current = $(this)
target = current.attr('href')
if (target.startsWith('#'))
{
if (first)
{
first = false;
current.data('from', 0);
} else
{
let top = $(target).position().top;
console.log(top);
current.data('from', top);
previous.data('to', top);
}
previous = current;
}
});
previous.data('to', Number.POSITIVE_INFINITY);
$(window).on("scroll", function()
{
let offset = $('header').height() + $('.slides nav.menu').height();
let current = $(window).scrollTop() + offset;
$('.slides nav.menu li a').each(function()
{
let a = $(this);
console.log(a.attr('href'), a.data('from'), a.data('to'), current);
let from = a.data('from');
let to = a.data('to');
// subtract the navbar height from the top of the section
if(from < current && current < to)
{
a.parent().addClass('active');
} else
{
a.parent().removeClass('active');
}
});
});
$(window).scroll();
});