Skip to content

Commit

Permalink
Add set_bottom option
Browse files Browse the repository at this point in the history
  • Loading branch information
hisas committed Aug 17, 2017
1 parent f306732 commit de8c1df
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 18 deletions.
38 changes: 24 additions & 14 deletions dist/sticky-kit.js

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

42 changes: 41 additions & 1 deletion spec/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,48 @@ describe "sticky columns", ->
expect(top cell).toBe 22
expect(cell.is(".is_stuck")).toBe false
]

it "uses set_bottom", (done) ->
write_iframe("""
<div class="stick_header">
<div class="stick_cell header"></div>
<div class="stick_body"></div>
</div>
<script type="text/javascript">
var navibar_height = 40
$(".stick_cell").stick_in_parent({offset_top: $(window).height() - navibar_height, set_bottom: true, navibar_height: navibar_height})
</script>
""").then (f) ->
cell = f.find(".stick_cell")

# f.on "scroll", => console.warn f.scrollTop(), top cell

scroll_each f, done, [
at 5, =>
expect(cell.is(".is_stuck")).toBe true
expect(cell.css("bottom")).toBe "0px"

at 15, =>
expect(cell.is(".is_stuck")).toBe true
expect(cell.css("bottom")).toBe "0px"

at 40, =>
expect(cell.is(".is_stuck")).toBe true
expect(cell.css("bottom")).toBe "0px"

at 125, =>
expect(cell.is(".is_stuck")).toBe true
expect(cell.css("bottom")).toBe "0px"

at 15, =>
expect(cell.is(".is_stuck")).toBe true
expect(cell.css("bottom")).toBe "0px"

at 0, =>
expect(cell.is(".is_stuck")).toBe true
expect(cell.css("bottom")).toBe "0px"
]

describe "events", ->
it "detects events when scrolling sticky header", (done) ->
Expand Down Expand Up @@ -719,4 +760,3 @@ scroll_each = (f, done, points) ->
done()

scroll_to_next()

10 changes: 7 additions & 3 deletions sticky-kit.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ $.fn.stick_in_parent = (opts={}) ->
offset_top
spacer: manual_spacer
bottoming: enable_bottoming
set_bottom
navibar_height
} = opts

win_height = win.height()
Expand Down Expand Up @@ -92,7 +94,7 @@ $.fn.stick_in_parent = (opts={}) ->

restore = true

top = elm.offset().top - (parseInt(elm.css("margin-top"), 10) or 0) - offset_top
top = if set_bottom then 0 else elm.offset().top - (parseInt(elm.css("margin-top"), 10) or 0) - offset_top

height = elm.outerHeight true

Expand All @@ -114,6 +116,10 @@ $.fn.stick_in_parent = (opts={}) ->
last_pos = undefined
offset = offset_top

if set_bottom
win.resize ->
offset = offset_top = win.height() - navibar_height

recalc_counter = recalc_every

tick = ->
Expand Down Expand Up @@ -265,5 +271,3 @@ $.fn.stick_in_parent = (opts={}) ->

) $ elm
@


0 comments on commit de8c1df

Please sign in to comment.