Skip to content

Commit

Permalink
add offset parameter leafo#1 leafo#2
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Sep 11, 2013
1 parent 252e56e commit bfeccbd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
14 changes: 7 additions & 7 deletions jquery.sticky-kit.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ $ = @jQuery

win = $ window
$.fn.stick_in_parent = (opts={}) ->
{ sticky_class, inner_scrolling, parent: parent_selector } = opts
{ sticky_class, inner_scrolling, parent: parent_selector, offset_top } = opts
offset_top ?= 0
parent_selector ?= undefined
inner_scrolling ?= true
sticky_class ?= "is_stuck"
Expand All @@ -30,7 +31,7 @@ $.fn.stick_in_parent = (opts={}) ->
else
elm

top = sizing_elm.offset().top - parseInt sizing_elm.css("margin-top"), 10
top = sizing_elm.offset().top - parseInt(sizing_elm.css("margin-top"), 10) - offset_top
height = sizing_elm.outerHeight true

recalc()
Expand All @@ -50,7 +51,7 @@ $.fn.stick_in_parent = (opts={}) ->
fixed = false
bottomed = false
last_pos = undefined
offset = 0
offset = offset_top
reset_width = false

tick = ->
Expand All @@ -68,13 +69,13 @@ $.fn.stick_in_parent = (opts={}) ->
elm.css({
position: "fixed"
bottom: ""
top: 0
top: offset
}).trigger("sticky_kit:unbottom")

# unfixing
if scroll < top
fixed = false
offset = 0
offset = offset_top

if float == "left" || float == "right"
elm.insertAfter spacer
Expand All @@ -92,9 +93,8 @@ $.fn.stick_in_parent = (opts={}) ->
if height > win_height # bigger than viewport
unless bottomed
offset -= delta
before = offset
offset = Math.max win_height - height, offset
offset = Math.min 0, offset
offset = Math.min offset_top, offset

elm.css {
top: offset + "px"
Expand Down
20 changes: 11 additions & 9 deletions jquery.sticky-kit.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bfeccbd

Please sign in to comment.