-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
66 lines (52 loc) · 2.2 KB
/
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
(function ($) {
$(function () {
$(window).on('scroll', function () {
fnOnScroll();
});
$(window).on('resize', function () {
fnOnResize();
});
var agTimeline = $('.js-timeline'),
agTimelineLine = $('.js-timeline_line'),
agTimelineLineProgress = $('.js-timeline_line-progress'),
agTimelinePoint = $('.js-timeline-card_point-box'),
agTimelineItem = $('.js-timeline_item'),
agOuterHeight = $(window).outerHeight(),
agHeight = $(window).height(),
f = -1,
agFlag = false;
function fnOnScroll() {
agPosY = $(window).scrollTop();
fnUpdateFrame();
}
function fnOnResize() {
agPosY = $(window).scrollTop();
agHeight = $(window).height();
fnUpdateFrame();
}
function fnUpdateWindow() {
agFlag = false;
agTimelineLine.css({
top: agTimelineItem.first().find(agTimelinePoint).offset().top - agTimelineItem.first().offset().top,
bottom: agTimeline.offset().top + agTimeline.outerHeight() - agTimelineItem.last().find(agTimelinePoint).offset().top
});
f !== agPosY && (f = agPosY, agHeight, fnUpdateProgress());
}
function fnUpdateProgress() {
var agTop = agTimelineItem.last().find(agTimelinePoint).offset().top;
i = agTop + agPosY - $(window).scrollTop();
a = agTimelineLineProgress.offset().top + agPosY - $(window).scrollTop();
n = agPosY - a + agOuterHeight / 2;
i <= agPosY + agOuterHeight / 2 && (n = i - a);
agTimelineLineProgress.css({ height: n + "px" });
agTimelineItem.each(function () {
var agTop = $(this).find(agTimelinePoint).offset().top;
(agTop + agPosY - $(window).scrollTop()) < agPosY + .5 * agOuterHeight ? $(this).addClass('js-ag-active') : $(this).removeClass('js-ag-active');
})
}
function fnUpdateFrame() {
agFlag || requestAnimationFrame(fnUpdateWindow);
agFlag = true;
}
});
})(jQuery);