1
1
### *
2
- @license Sticky-kit v1.1.3 | MIT | Leaf Corcoran 2015 | http://leafo.net
2
+ @license Sticky-kit v1.1.4 | MIT | Leaf Corcoran 2015 | http://leafo.net
3
3
###
4
4
5
5
$ = window .jQuery
6
6
7
7
win = $ window
8
+ doc = $ document
9
+
8
10
$ .fn .stick_in_parent = (opts = {}) ->
9
11
{
10
12
sticky_class
@@ -16,13 +18,14 @@ $.fn.stick_in_parent = (opts={}) ->
16
18
bottoming : enable_bottoming
17
19
} = opts
18
20
21
+ win_height = win .height ()
22
+ doc_height = doc .height ()
23
+
19
24
offset_top ?= 0
20
25
parent_selector ?= undefined
21
26
inner_scrolling ?= true
22
27
sticky_class ?= " is_stuck"
23
28
24
- doc = $ (document )
25
-
26
29
enable_bottoming = true unless enable_bottoming?
27
30
28
31
# we need this because jquery's version (along with css()) rounds everything
@@ -44,7 +47,7 @@ $.fn.stick_in_parent = (opts={}) ->
44
47
return if elm .data " sticky_kit"
45
48
elm .data " sticky_kit" , true
46
49
47
- last_scroll_height = doc . height ()
50
+ last_scroll_height = doc_height
48
51
49
52
parent = elm .parent ()
50
53
parent = parent .closest (parent_selector) if parent_selector?
@@ -61,7 +64,9 @@ $.fn.stick_in_parent = (opts={}) ->
61
64
62
65
recalc = ->
63
66
return if detached
64
- last_scroll_height = doc .height ()
67
+ win_height = win .height ();
68
+ doc_height = doc .height ();
69
+ last_scroll_height = doc_height
65
70
66
71
border_top = parseInt parent .css (" border-top-width" ), 10
67
72
padding_top = parseInt parent .css (" padding-top" ), 10
@@ -122,7 +127,7 @@ $.fn.stick_in_parent = (opts={}) ->
122
127
recalc ()
123
128
recalced = true
124
129
125
- if ! recalced && doc . height () != last_scroll_height
130
+ if ! recalced && doc_height != last_scroll_height
126
131
recalc ()
127
132
recalced = true
128
133
@@ -164,7 +169,6 @@ $.fn.stick_in_parent = (opts={}) ->
164
169
165
170
# updated offset
166
171
if inner_scrolling
167
- win_height = win .height ()
168
172
if height + offset_top > win_height # bigger than viewport
169
173
unless bottomed
170
174
offset -= delta
0 commit comments