File tree Expand file tree Collapse file tree 1 file changed +38
-3
lines changed Expand file tree Collapse file tree 1 file changed +38
-3
lines changed Original file line number Diff line number Diff line change 97
97
}
98
98
99
99
/*
100
- * Scroll Event
100
+ * Throttle function borrowed from:
101
+ * Underscore.js 1.5.2
102
+ * http://underscorejs.org
103
+ * (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
104
+ * Underscore may be freely distributed under the MIT license.
101
105
*/
102
106
103
- $window . on ( 'scroll.scrollDepth' , function ( ) {
107
+ function throttle ( func , wait ) {
108
+ var context , args , result ;
109
+ var timeout = null ;
110
+ var previous = 0 ;
111
+ var later = function ( ) {
112
+ previous = new Date ;
113
+ timeout = null ;
114
+ result = func . apply ( context , args ) ;
115
+ } ;
116
+ return function ( ) {
117
+ var now = new Date ;
118
+ if ( ! previous ) previous = now ;
119
+ var remaining = wait - ( now - previous ) ;
120
+ context = this ;
121
+ args = arguments ;
122
+ if ( remaining <= 0 ) {
123
+ clearTimeout ( timeout ) ;
124
+ timeout = null ;
125
+ previous = now ;
126
+ result = func . apply ( context , args ) ;
127
+ } else if ( ! timeout ) {
128
+ timeout = setTimeout ( later , remaining ) ;
129
+ }
130
+ return result ;
131
+ } ;
132
+ }
133
+
134
+ /*
135
+ * Scroll Event
136
+ */
104
137
138
+ $window . on ( 'scroll.scrollDepth' , throttle ( function ( ) {
139
+ console . log ( 'foo' ) ;
105
140
/*
106
141
* We calculate document and window height on each scroll event to
107
142
* account for dynamic DOM changes.
132
167
if ( options . percentage ) {
133
168
checkMarks ( marks , scrollDistance , timing ) ;
134
169
}
135
- } ) ;
170
+ } , 500 ) ) ;
136
171
137
172
} ;
138
173
You can’t perform that action at this time.
0 commit comments