Connecting Tech Pros Worldwide Help | Site Map

Floating div

  #1  
Old July 23rd, 2005, 12:17 PM
Simon Wigzell
Guest
 
Posts: n/a
How do a create a floating div that will always stay in the same place
relative to the browser window as the user scrolls the main page? I guess an
adaptation of one of these floating menus that always stay in view would
work but I just need the few lines of code to keep it positioned a certain x
and y pix location from the window top left corner... Thanks!


  #2  
Old July 23rd, 2005, 12:17 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a

re: Floating div


Simon Wigzell wrote:
[color=blue]
> How do a create a floating div that will always stay in the same place
> relative to the browser window as the user scrolls the main page?[/color]

CSS2's position:fixed and a proper workaround for non-compliant
browsers. This has nothing to do with J(ava)Script, ask in
comp.infosystems.www.authoring.stylesheets.


PointedEars
  #3  
Old July 23rd, 2005, 12:17 PM
JimMenees
Guest
 
Posts: n/a

re: Floating div


Simon,
This is called a 'watermark' script; there are several examples on the web.
Here's a few URL's with the explanation and info on this javascript/dhtml tool:

http://www.javascript-page.com/watermark.html

http://www.dynamicdrive.com/dynamicindex4/logo.htm

http://www.ricocheting.com/js/watermark.html

Hope this helps!

Jim
  #4  
Old July 23rd, 2005, 12:17 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a

re: Floating div


JimMenees wrote:
[color=blue]
> This is called a 'watermark' script; there are several examples on the web.
> Here's a few URL's with the explanation and info on this javascript/dhtml tool:
> [...][/color]

"Watermark scripts" have been utter nonsense since they have been conceived,
and eventually are utter nonsense since they are outdated. CSS2 provides
this feature much more reliable and performant.


PointedEars
  #5  
Old July 23rd, 2005, 12:17 PM
Lasse Reichstein Nielsen
Guest
 
Posts: n/a

re: Floating div


"Simon Wigzell" <simonwigzell@shaw.ca> writes:
[color=blue]
> How do a create a floating div that will always stay in the same place
> relative to the browser window as the user scrolls the main page? I guess an
> adaptation of one of these floating menus that always stay in view would
> work but I just need the few lines of code to keep it positioned a certain x
> and y pix location from the window top left corner... Thanks![/color]

Use CSS 2 position:fixed for browsers that support it (all modern
browsers), and use a fallback for older browsers (including all IE
versions). The fallback is based on detecting scrolling and
repositioning the element. I would usually only bother putting in a
fallback for IE 5+, using IE conditional comments:

---
<style type="text/css">
#myfixed {
position: fixed;
top: 100px;
left: 50px;
}
</style>
<!--[if IE]>
<style type="text/css">
#myfixed { position:absolute; }
</style>
<script type="text/javascript">
window.onscroll = function() {
var root = (document.compatMode == "CSS1Compat"?
document.documentElement: document.body);
var elem = document.all["myfixed"];
elem.style.left = root.scrollLeft + 50 + "px";
elem.style.top = root.scrollTop + 100 + "px";
};
</script>
<![endif]-->
....
<div id="myfixed" style="width:100px;height:100px;border:1px solid black;">
HERE<br>I<br>AM
</div>
---

/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
  #6  
Old July 23rd, 2005, 12:18 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a

re: Floating div


Lasse Reichstein Nielsen wrote:
[color=blue]
> "Simon Wigzell" <simonwigzell@shaw.ca> writes:[color=green]
>> How do a create a floating div that will always stay in the same place
>> relative to the browser window as the user scrolls the main page? I guess an
>> adaptation of one of these floating menus that always stay in view would
>> work but I just need the few lines of code to keep it positioned a certain x
>> and y pix location from the window top left corner... Thanks![/color]
>
> Use CSS 2 position:fixed for browsers that support it (all modern
> browsers), and use a fallback for older browsers (including all IE
> versions). The fallback is based on detecting scrolling and
> repositioning the element. I would usually only bother putting in a
> fallback for IE 5+, using IE conditional comments:[/color]

There are workarounds for IE 5+ that work without JScript.
Conditional comments are an important part of it, though.

<http://www.fabrice-pascal.de/artikel/posfixedie6/>

<http://translate.google.com/translate?u=http://www.fabrice-pascal.de/artikel/posfixedie6/&langpair=de%7Cen&hl=en&ie=Unknown&oe=ISO-8859-1>
(Beware of the [awful] translation, it translates the stylesheets as well!)


X-Post & F'up2 comp.infosystems.www.authoring.stylesheets

PointedEars
  #7  
Old July 23rd, 2005, 12:18 PM
Simon Wigzell
Guest
 
Posts: n/a

re: Floating div


Thanks to all who replied, my problem is resolved.


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
page event to hide floating div Jeremy answers 6 June 27th, 2008 08:13 PM
Floating DIV positioning. How much does the order matter? Viken Karaguesian answers 2 December 30th, 2005 12:55 AM
Floating div problem NoSpan answers 10 July 21st, 2005 01:10 AM
floating div's and lists James Walker answers 1 July 21st, 2005 12:10 AM
Whoever it was that suggested a floating DIV instead of a chromeless window George Hester answers 1 July 20th, 2005 01:40 PM