Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a DIV always at the bottom of the page when scrolling

I am using the below code to make a DIV always at the bottom of the page when scrolled. But this is not working and goes on increasing the Page height.

var LSscrollingDiv = $("#LightSwitchMenuIt");
$(window).scroll(function(){
  LSscrollingDiv
      .stop()
      .animate({"marginTop": ($(window).scrollTop() + $(window).height()) + "px"}, "slow" );            
});

Please help me on this.

like image 884
Exception Avatar asked Jan 20 '12 14:01

Exception


People also ask

How do I make DIVS stay in one place when scrolling?

Use position fixed. Position fixed makes it so that an element stays at it's specified place even if the user scrolls up or down.

How do you position a div at the bottom right of the page?

To place a div in bottom right corner of browser or iframe, we can use position:fixed along with right and bottom property value assigned to 0.


4 Answers

Why not use straight CSS?

div.foo {
    position: fixed;
    bottom: 0px;  
}

Demo.

See:

  • https://developer.mozilla.org/de/CSS/position
like image 57
karim79 Avatar answered Oct 25 '22 19:10

karim79


This might be a simple CSS issue ... you can place a DIV to a fixed position at the bottom of the viewport and it will always be there when scrolling, without any Javascript

position: fixed;
bottom: 0px;
like image 43
devnull69 Avatar answered Oct 25 '22 18:10

devnull69


You can use css

position: fixed;
bottom: 0;

to avoid having to do this in javascript if you like.

http://jsfiddle.net/A8BGJ/ is a simple demonstration.

like image 27
minikomi Avatar answered Oct 25 '22 19:10

minikomi


It may help to have width set as inherit too.

#div {
position: fixed;
bottom: 0;
width: inherit;
}
like image 40
user2727099 Avatar answered Oct 25 '22 19:10

user2727099