Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set_bottom option #243

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 bar_height = 40
$(".stick_cell").stick_in_parent({offset_top: $(window).height() - bar_height, set_bottom: true, bar_height: bar_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
bar_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() - bar_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
@