Reputation: 143
I want to position an element so that it is always some fixed distance from the top of the browser so that even if the user scrolls down, the image will always be the same distance from the top of the screen. How do I do this?
Upvotes: 2
Views: 6898
Reputation: 298046
No jQuery needed here. Pure CSS will suffice:
#element {
position: fixed;
top: 100px;
}
But if you insist on a jQuery solution, the code below sets the CSS via jQuery:
$('#element').css({'position': 'fixed', 'top': '100px'});
Upvotes: 8