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

I use the code below to make the DIV always at the bottom of the page when scrolling. But this does not work and continues to increase the page height.

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

Please help me with this.

+6
source share
5 answers

Why not use straight CSS?

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

Demo

Cm:

+20
source

This might be a simple CSS problem ... you can put the DIV in a fixed position at the bottom of the viewport and always be there when scrolling, without Javascript

 position: fixed; bottom: 0px; 
+6
source

You can use css

 position: fixed; bottom: 0; 

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

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

+2
source

It can also help set the width as inheritance.

 #div { position: fixed; bottom: 0; width: inherit; } 
+2
source

Use the following rules:

 div { position: fixed; bottom: 0; } 

You can also use this technique in any parent block element.

+1
source

Source: https://habr.com/ru/post/906483/


All Articles