1 | $().ready(() => {
|
2 | const verticalSections = $('.vertical-section')
|
3 |
|
4 | |
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | const positionSectionHeader = (verticalSection, leftOffset) => {
|
13 | const bottomOfASection = verticalSection.offset().top + verticalSection.height()
|
14 | const topOfASection = verticalSection.offset().top
|
15 | const sectionTitleHeight = verticalSection.find('.title').height()
|
16 | const isSectionCurrentlyViewed =
|
17 | window.pageYOffset > topOfASection &&
|
18 | window.pageYOffset < bottomOfASection
|
19 |
|
20 | if (isSectionCurrentlyViewed) {
|
21 |
|
22 | if (window.pageYOffset > ( bottomOfASection - sectionTitleHeight )) {
|
23 | verticalSection.find('.title').css({ left: 0, position: 'absolute', bottom: '0', top: 'auto'})
|
24 | } else {
|
25 | verticalSection.find('.title').css({ left: leftOffset, bottom: 'auto', position: 'fixed', top: 0})
|
26 | }
|
27 | } else {
|
28 |
|
29 | verticalSection.find('.title').css({ left: 0, position: 'absolute' })
|
30 | }
|
31 | }
|
32 |
|
33 | if (verticalSections.length > 0) {
|
34 | let leftOffset = verticalSections.offset().left
|
35 | $(window).resize((e) => {
|
36 | leftOffset = verticalSections.offset().left
|
37 | verticalSections.each((i, el) => {
|
38 | positionSectionHeader($(el), leftOffset)
|
39 | })
|
40 | })
|
41 | $(window).scroll((e) => {
|
42 | verticalSections.each((i, el) => {
|
43 | positionSectionHeader($(el), leftOffset)
|
44 | })
|
45 | })
|
46 | }
|
47 | }) |
\ | No newline at end of file |