Skip to content

Commit f306732

Browse files
authored
Merge pull request leafo#218 from jsit/height
Fixed height definitions that were causing layout trashing @enyce12 leafo#119
2 parents 1a3dd22 + fc5200c commit f306732

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

sticky-kit.coffee

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
###*
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
33
###
44

55
$ = window.jQuery
66

77
win = $ window
8+
doc = $ document
9+
810
$.fn.stick_in_parent = (opts={}) ->
911
{
1012
sticky_class
@@ -16,13 +18,14 @@ $.fn.stick_in_parent = (opts={}) ->
1618
bottoming: enable_bottoming
1719
} = opts
1820

21+
win_height = win.height()
22+
doc_height = doc.height()
23+
1924
offset_top ?= 0
2025
parent_selector ?= undefined
2126
inner_scrolling ?= true
2227
sticky_class ?= "is_stuck"
2328

24-
doc = $(document)
25-
2629
enable_bottoming = true unless enable_bottoming?
2730

2831
# we need this because jquery's version (along with css()) rounds everything
@@ -44,7 +47,7 @@ $.fn.stick_in_parent = (opts={}) ->
4447
return if elm.data "sticky_kit"
4548
elm.data "sticky_kit", true
4649

47-
last_scroll_height = doc.height()
50+
last_scroll_height = doc_height
4851

4952
parent = elm.parent()
5053
parent = parent.closest(parent_selector) if parent_selector?
@@ -61,7 +64,9 @@ $.fn.stick_in_parent = (opts={}) ->
6164

6265
recalc = ->
6366
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
6570

6671
border_top = parseInt parent.css("border-top-width"), 10
6772
padding_top = parseInt parent.css("padding-top"), 10
@@ -122,7 +127,7 @@ $.fn.stick_in_parent = (opts={}) ->
122127
recalc()
123128
recalced = true
124129

125-
if !recalced && doc.height() != last_scroll_height
130+
if !recalced && doc_height != last_scroll_height
126131
recalc()
127132
recalced = true
128133

@@ -164,7 +169,6 @@ $.fn.stick_in_parent = (opts={}) ->
164169

165170
# updated offset
166171
if inner_scrolling
167-
win_height = win.height()
168172
if height + offset_top > win_height # bigger than viewport
169173
unless bottomed
170174
offset -= delta

0 commit comments

Comments
 (0)