Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matherton/2351968 to your computer and use it in GitHub Desktop.
Save matherton/2351968 to your computer and use it in GitHub Desktop.
coffee scrip - relative and fixed positioning dependant on if div is viewable on screen
# code for the advert preview and the "why go premium list" on the create new ad form so that it only adopts fixed positioning when all of it is in view.
$ ->
e = $("div#advert_preview")
jWindow = $(window)
offsetTop = e.offset().top
positionTop = e.position().top
jWindow.scroll ->
if jWindow.scrollTop() > offsetTop
e.css
position: "fixed"
top: 0
else
e.css
position: "relative"
top: positionTop
# code for the advert preview and the "why go premium list" on the create new ad form so that it only adopts fixed positioning when all of it is in view.
$ ->
e = $("div#advert_preview")
jWindow = $(window)
offsetTop = e.offset().top
positionTop = e.position().top
jWindow.scroll ->
if jWindow.scrollTop() > offsetTop
e.css
position: "fixed"
top: 0
else
e.css
position: "relative"
top: positionTop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment