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

min_width option so element is always unstuck in smaller viewports #149

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 12 additions & 3 deletions sticky-kit.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ $.fn.stick_in_parent = (opts={}) ->
inner_scrolling
recalc_every
parent: parent_selector
offset_top
offset_top,
min_width,
spacer: manual_spacer
bottoming: enable_bottoming
} = opts

offset_top ?= 0
min_width ?= 0
parent_selector ?= undefined
inner_scrolling ?= true
sticky_class ?= "is_stuck"
Expand Down Expand Up @@ -131,6 +133,13 @@ $.fn.stick_in_parent = (opts={}) ->
delta = scroll - last_pos
last_pos = scroll

viewport_width = Math.max(document.documentElement.clientWidth, window.innerWidth or 0)
always_unstuck = false

if viewport_width < min_width
fixed = false
always_unstuck = true

if fixed
if enable_bottoming
will_bottom = scroll + height + offset > parent_height + parent_top
Expand All @@ -145,7 +154,7 @@ $.fn.stick_in_parent = (opts={}) ->
}).trigger("sticky_kit:unbottom")

# unfixing
if scroll < top
if scroll < top or always_unstuck
fixed = false
offset = offset_top

Expand Down Expand Up @@ -178,7 +187,7 @@ $.fn.stick_in_parent = (opts={}) ->

else
# fixing
if scroll > top
if scroll > top and !always_unstuck
fixed = true
css = {
position: "fixed"
Expand Down