Topic awaiting preservation: Smart Floating Box - how to determine height of div? (Page 1 of 1) |
|
---|---|
Nervous Wreck (II) Inmate From: Careywood, Idaho, USA |
posted 12-24-2005 08:00
Hello everyone! code: <div id="leftSideBar" style="position:relative;"> !BOX CONTENT! </div> <script language="Javascript"> <!-- function floatSideBar(blah) { var pY,nY,id=\'leftSideBar\'; pY=(navigator.appName.indexOf("Netscape")!=-1)?pageYOffset:nn&&document.html.scrollTop?document.html.scrollTop:document.body.scrollTop; //pY -= document.getElementById(id).style.pixelHeight; //nY += 0.1 * (pY-nY); nY = pY; document.getElementById(id).style.top = nY+\'px\'; setTimeout(\'floatSideBar()\',100); }; floatSideBar(); //--> </script>
|
Maniac (V) Mad Scientist From: :morF |
posted 12-24-2005 10:14
Well, why not set the box's style property to overflow-y: auto; or overflow-y: scroll? That way it will offer them a scroll-bar if the content overflows the set, static height for the box. Then all you need do is make sure that the box is less than, say, 400px high, and then everyone will always be able to see it, even if they're at 640x480. |
Paranoid (IV) Mad Librarian From: GlieBeGe |
posted 12-24-2005 12:20
'cause that would only be half as nice, Skaarjj... |
Nervous Wreck (II) Inmate From: Careywood, Idaho, USA |
posted 12-24-2005 16:57
Skaarj: |
Nervous Wreck (II) Inmate From: Careywood, Idaho, USA |
posted 12-24-2005 19:08
I have it almost working... code: <script language="Javascript"> <!-- function floatSideBar(bY,lPY) { //pageY, pageHeight, boxHeight, boxId var pY,pH,bH,id=\'leftSideBar\'; pY=(navigator.appName.indexOf("Netscape")!=-1)?pageYOffset:nn&&document.html.scrollTop?document.html.scrollTop:document.body.scrollTop; if(pY != lPY) { //they scrolled //pH = document.body.offsetHeight; //else if (document.layers) pH = window.innerHeight; pH = 700; bH = document.getElementById(id).offsetHeight; if(pY < bY) { //need to move box up bY = pY; document.getElementById(id).style.top = bY+\'px\'; } else if(pY + pH > bY + bH) { //need to move box down bY = pY + pH - bY; document.getElementById(id).style.top = bY+\'px\'; } } setTimeout(\'floatSideBar(\\\'\'+bY+\'\\\',\\\'\'+pY+\'\\\')\',100); }; floatSideBar(140,0); //--> </script>
|
Nervous Wreck (II) Inmate From: Careywood, Idaho, USA |
posted 12-31-2005 06:46
I almost have this working, we can't let it die now! code: <div id="leftSideBar" style="position:absolute;"> content here! </div>
|