Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-14-2005, 01:00 PM   PM User | #1
crmpicco
Senior Coder

 
crmpicco's Avatar
 
Join Date: Jan 2005
Location: Mauchline, Scotland
Posts: 1,091
Thanks: 15
Thanked 1 Time in 1 Post
crmpicco has a little shameless behaviour in the past
Unhappy make div stick to the BOTTOM of the browser as you scroll

Code:
function movediv()
{
	booking_details.style.top = document.body.scrollTop;
}

---------------

<style>
.demo {color:#000000; border-color:#666666; background-color:#FFCC00; font-family:Verdana, Arial, Helvetica, sans-serif; font-weight:bold;
layer-background-color:#cccccc; position:absolute; left:12.5%; bottom:0px; width:100%; height:100px; visibility:hidden; z-index:5; border-color:#FFFFFF; border:inherit;}
</style>

---------------

<body onScroll="movediv();">

<div id="booking_details" class="demo" style="visibility:hidden">
....
.... code .....
....
</div>

</body>
When i scroll the DIV sticks to the TOP of the browser, is there any way to
make it sticks to the BOTTOM of the browser as you scroll?
crmpicco is offline   Reply With Quote
Old 09-14-2005, 03:31 PM   PM User | #2
crazygamer
New Coder

 
Join Date: Sep 2005
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
crazygamer is an unknown quantity at this point
<div id="myDiv"></div>
<script>
var winHeight;
if ( window.innerHeight ) {
winHeight = window.innerHeight;
}
else if ( document.body.clientHeight ) {
winHeight = document.body.clientHeight;
}

myDiv = document.getElementById("myDiv");
myDiv.style.top = winHeight - myDiv.height;
</script>

Let me know if that works, I pulled it off the top of my head because I'm in a rush (anotherwords, it's NOT tested). Should work in IE and Firefox, probably most other browsers.
crazygamer is offline   Reply With Quote
Old 09-14-2005, 04:22 PM   PM User | #3
rm-f
Regular Coder

 
Join Date: Aug 2005
Location: Toronto, ON, Canada
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
rm-f is an unknown quantity at this point
FF example, see crazygamer's comment for cross browser compatibility.

Code:
<html>
<head>
    <title>Div on Bottom</title>
    <script>
        function movediv() {
            var divElem = document.getElementById('booking_details');
            divElem.style.top = (window.scrollY + window.innerHeight - parseInt(divElem.style.height)) + 'px';
        }
        function stupid() {
            document.getElementById('booking_details').style.height = '100px';
            movediv();  //sync reload
        }
    </script>
    <style type="text/css">
        #booking_details {
            color: #000000; 
            border-color: #666666; 
            background-color: #FFCC00; 
            font-family: Verdana, Arial, Helvetica, sans-serif; 
            font-weight: bold;
            layer-background-color: #cccccc; 
            position: absolute; 
            left:12.5%; 
            bottom:0px; 
            width: 87.5%; 
            height: 100px;
            /*
            visibility:hidden; 
            */
            z-index:5; 
            border-color:#FFFFFF; 
            border:inherit;
        }
    </style>    
</head>
<body onload="stupid();" onscroll="movediv();">
<div id="booking_details">
Stay on Bottom of the Page
</div>
<script>
for(var i=0; i<100; i++) {
    document.write('line: ' + i + '<br>');
}
</script>
</body>
</html>
__________________
rm -f /
rm-f is offline   Reply With Quote
Old 10-01-2009, 02:42 AM   PM User | #4
hassan
New to the CF scene

 
Join Date: Oct 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
hassan is an unknown quantity at this point
hey ,

you do not need to use in script you can use only CSS to make that happens.

#mydiv {
position: fixed;
z-index: 2;
bottom: 0px;

}


let me know if it works for you.

Hassan
hassan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:38 PM.


Advertisement
Log in to turn off these ads.