Reputation: 150
I want to fix the body but there is a automatically scroll to the top of the document and I can't return where I was.
Do you know how I can scroll in a fixed body ?
This is the plunker : http://plnkr.co/edit/UBDtXTLX1Mdl35TU6XyW?p=preview
with the code jQuery :
var topBody = $(window).scrollTop();
$("body").css("position","fixed");
$('html, body').animate( { scrollTop: topBody }, 0 );
Upvotes: 0
Views: 396
Reputation: 1374
Are you looking for something like this: plunker?
$(function() {
function fixedthebody() {
var position = window.pageYOffset;
$(".sample").css({
"position": "fixed",
"height": "100%",
"overflow-x": "hidden"
}).animate({
scrollTop: position
}, 0);
}
button.onclick = fixedthebody;
});
Upvotes: 1
Reputation: 66
Make everything inside a div with overflow as scroll inside the body. That will make a srollbar inside the fixed body.
ie
<body>
<div style="overflow:scroll">
<!-- ALL THE CODE HERE-->
</div>
<body>
Upvotes: 0