@@ -7,6 +7,8 @@ $ = window.jQuery
7
7
win = $ window
8
8
doc = $ document
9
9
10
+ scroll_container = win;
11
+
10
12
$ .fn .stick_in_parent = (opts = {}) ->
11
13
{
12
14
sticky_class
@@ -16,6 +18,7 @@ $.fn.stick_in_parent = (opts={}) ->
16
18
offset_top
17
19
spacer : manual_spacer
18
20
bottoming : enable_bottoming
21
+ container
19
22
} = opts
20
23
21
24
win_height = win .height ()
@@ -28,6 +31,8 @@ $.fn.stick_in_parent = (opts={}) ->
28
31
29
32
enable_bottoming = true unless enable_bottoming?
30
33
34
+ scroll_container = $ container if container?
35
+
31
36
# we need this because jquery's version (along with css()) rounds everything
32
37
outer_width = (el ) ->
33
38
if window .getComputedStyle
@@ -131,7 +136,7 @@ $.fn.stick_in_parent = (opts={}) ->
131
136
recalc ()
132
137
recalced = true
133
138
134
- scroll = win .scrollTop ()
139
+ scroll = scroll_container .scrollTop ()
135
140
if last_pos?
136
141
delta = scroll - last_pos
137
142
last_pos = scroll
@@ -230,9 +235,9 @@ $.fn.stick_in_parent = (opts={}) ->
230
235
231
236
detach = ->
232
237
detached = true
233
- win .off " touchmove " , tick
234
- win .off " scroll " , tick
235
- win .off " resize" , recalc_and_tick
238
+ scroll_container .off " scroll " , tick
239
+ scroll_container .off " touchmove " , tick
240
+ scroll_container .off " resize" , recalc_and_tick
236
241
237
242
$ (document .body ).off " sticky_kit:recalc" , recalc_and_tick
238
243
elm .off " sticky_kit:detach" , detach
@@ -255,9 +260,10 @@ $.fn.stick_in_parent = (opts={}) ->
255
260
256
261
elm .removeClass sticky_class
257
262
258
- win .on " touchmove" , tick
259
- win .on " scroll" , tick
260
- win .on " resize" , recalc_and_tick
263
+ scroll_container .on " scroll" , tick
264
+ scroll_container .on " touchmove" , tick
265
+ scroll_container .on " resize" , recalc_and_tick
266
+
261
267
$ (document .body ).on " sticky_kit:recalc" , recalc_and_tick
262
268
elm .on " sticky_kit:detach" , detach
263
269
0 commit comments