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 18, 2017
1 parent f306732 commit b393053
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 18 deletions.
36 changes: 23 additions & 13 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()

12 changes: 8 additions & 4 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 All @@ -127,7 +133,7 @@ $.fn.stick_in_parent = (opts={}) ->
recalc()
recalced = true

if !recalced && doc_height != last_scroll_height
if !recalced && doc.height() != last_scroll_height
recalc()
recalced = true

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

) $ elm
@


0 comments on commit b393053

Please sign in to comment.