Created
April 10, 2012 14:56
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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