Skip to content

Commit de8c1df

Browse files
committed
Add set_bottom option
1 parent f306732 commit de8c1df

File tree

3 files changed

+72
-18
lines changed

3 files changed

+72
-18
lines changed

dist/sticky-kit.js

Lines changed: 24 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/index.coffee

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,48 @@ describe "sticky columns", ->
499499
expect(top cell).toBe 22
500500
expect(cell.is(".is_stuck")).toBe false
501501
]
502+
503+
it "uses set_bottom", (done) ->
504+
write_iframe("""
505+
<div class="stick_header">
506+
<div class="stick_cell header"></div>
507+
<div class="stick_body"></div>
508+
</div>
509+
<script type="text/javascript">
510+
var navibar_height = 40
511+
$(".stick_cell").stick_in_parent({offset_top: $(window).height() - navibar_height, set_bottom: true, navibar_height: navibar_height})
512+
</script>
513+
514+
""").then (f) ->
515+
cell = f.find(".stick_cell")
516+
517+
# f.on "scroll", => console.warn f.scrollTop(), top cell
518+
519+
scroll_each f, done, [
520+
at 5, =>
521+
expect(cell.is(".is_stuck")).toBe true
522+
expect(cell.css("bottom")).toBe "0px"
523+
524+
at 15, =>
525+
expect(cell.is(".is_stuck")).toBe true
526+
expect(cell.css("bottom")).toBe "0px"
527+
528+
at 40, =>
529+
expect(cell.is(".is_stuck")).toBe true
530+
expect(cell.css("bottom")).toBe "0px"
502531

532+
at 125, =>
533+
expect(cell.is(".is_stuck")).toBe true
534+
expect(cell.css("bottom")).toBe "0px"
535+
536+
at 15, =>
537+
expect(cell.is(".is_stuck")).toBe true
538+
expect(cell.css("bottom")).toBe "0px"
539+
540+
at 0, =>
541+
expect(cell.is(".is_stuck")).toBe true
542+
expect(cell.css("bottom")).toBe "0px"
543+
]
503544

504545
describe "events", ->
505546
it "detects events when scrolling sticky header", (done) ->
@@ -719,4 +760,3 @@ scroll_each = (f, done, points) ->
719760
done()
720761

721762
scroll_to_next()
722-

sticky-kit.coffee

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ $.fn.stick_in_parent = (opts={}) ->
1616
offset_top
1717
spacer: manual_spacer
1818
bottoming: enable_bottoming
19+
set_bottom
20+
navibar_height
1921
} = opts
2022

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

9395
restore = true
9496

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

9799
height = elm.outerHeight true
98100

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

119+
if set_bottom
120+
win.resize ->
121+
offset = offset_top = win.height() - navibar_height
122+
117123
recalc_counter = recalc_every
118124

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

266272
) $ elm
267273
@
268-
269-

0 commit comments

Comments
 (0)