Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 12:17 PM
Simon Wigzell
Guest
 
Posts: n/a
Default Floating div

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
Default 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
Default 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
Default 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
Default 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
Default 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
Default Re: Floating div

Thanks to all who replied, my problem is resolved.


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.