@@ -14,59 +14,70 @@ define('globalNavigationScroll', [
14
14
winHeight ,
15
15
menuHeight = menu . height ( ) ,
16
16
menuHeightRest = 0 ,
17
+ menuScrollMax = 0 ,
17
18
contentHeight ,
18
19
winTop = 0 ,
19
20
winTopLast = 0 ,
20
21
scrollStep = 0 ,
21
22
nextTop = 0 ,
22
23
fixedClass = '_fixed' ;
23
24
25
+ /**
26
+ * Check if menu is fixed
27
+ * @returns {boolean }
28
+ */
24
29
function isMenuFixed ( ) {
25
30
return ( menuHeight < contentHeight ) && ( contentHeight > winHeight ) ;
26
31
}
27
32
33
+ /**
34
+ * Add fixed menu class
35
+ * @param {jQuery } el
36
+ */
28
37
function addFixed ( el ) {
29
38
if ( ! el . hasClass ( fixedClass ) ) {
30
39
el . addClass ( fixedClass ) ;
31
40
}
32
41
}
33
42
43
+ /**
44
+ * Remove fixed menu class
45
+ * @param {jQuery } el
46
+ */
34
47
function removeFixed ( el ) {
35
48
if ( el . hasClass ( fixedClass ) ) {
36
49
el . removeClass ( fixedClass ) ;
37
50
}
38
51
}
39
52
53
+ /**
54
+ * Calculate and apply menu position
55
+ */
40
56
function positionMenu ( ) {
41
57
42
- // Spot positions and heights
58
+ // Spotting positions and heights
43
59
winHeight = win . height ( ) ;
44
60
contentHeight = content . height ( ) ;
45
61
winTop = win . scrollTop ( ) ;
46
- scrollStep = winTop - winTopLast ; // scroll step
47
- menuHeightRest = menuHeight - winTop ; // visible menu height
62
+ scrollStep = winTop - winTopLast ;
63
+ menuHeightRest = menuHeight - winTop ; // is a visible menu height
48
64
49
- // Fixed menu cases
50
- if ( isMenuFixed ( ) ) {
65
+ if ( isMenuFixed ( ) ) { // fixed menu cases
51
66
52
67
addFixed ( menu ) ;
53
68
54
- // Smart scroll cases
55
- if ( menuHeight > winHeight ) {
69
+ if ( menuHeight > winHeight ) { // smart scroll cases
56
70
57
- // Scroll down
58
- if ( winTop > winTopLast ) {
71
+ if ( winTop > winTopLast ) { // scroll down
59
72
60
- var menuScrollMax = menuHeight - winHeight ;
73
+ menuScrollMax = menuHeight - winHeight ;
61
74
62
75
nextTop < ( menuScrollMax - scrollStep ) ?
63
76
nextTop += scrollStep : nextTop = menuScrollMax ;
64
77
65
78
menu . css ( 'top' , - nextTop ) ;
66
79
67
- }
68
- // Scroll up
69
- else if ( winTop < winTopLast ) {
80
+ } else if ( winTop < winTopLast ) { // scroll up
70
81
71
82
nextTop > - scrollStep ?
72
83
nextTop += scrollStep : nextTop = 0 ;
@@ -76,8 +87,8 @@ define('globalNavigationScroll', [
76
87
}
77
88
78
89
}
79
- // Static menu cases
80
- } else {
90
+
91
+ } else { // static menu cases
81
92
removeFixed ( menu ) ;
82
93
}
83
94
@@ -86,8 +97,7 @@ define('globalNavigationScroll', [
86
97
87
98
}
88
99
89
- // Page start calculation
90
- positionMenu ( ) ;
100
+ positionMenu ( ) ; // page start calculation
91
101
92
102
// Change position on scroll
93
103
win . on ( 'scroll' , function ( ) {
@@ -99,9 +109,7 @@ define('globalNavigationScroll', [
99
109
winHeight = win . height ( ) ;
100
110
101
111
// Reset position if fixed and out of smart scroll
102
- if (
103
- ( menuHeight < contentHeight ) && ( menuHeight <= winHeight )
104
- ) {
112
+ if ( ( menuHeight < contentHeight ) && ( menuHeight <= winHeight ) ) {
105
113
menu . removeAttr ( 'style' ) ;
106
114
}
107
115
0 commit comments