Martel Benjamin
Martel Benjamin

Reputation: 150

Position fixed to the body come back to the top

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

Answers (2)

NightOwlPrgmr
NightOwlPrgmr

Reputation: 1374

Are you looking for something like this: plunker?

jQuery code:

$(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

Minhaj Ahammed
Minhaj Ahammed

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

Related Questions