Solved

How to make a div that always stay on top

Posted on 2007-03-23
5
4,934 Views
Last Modified: 2012-08-13
Anyone has an idea about how to make a div which always stay on top right corner of the browser window, just like the red message saying "Loading..." on the top right corner of GMAIL ?

This can be achieve easily with Firefox and IE7. How about < IE6 ?
0
Comment
Question by:khoama
  • 3
5 Comments
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 18784143
What works in IE 7?

Maybe we can tweak it for IE 6 (which I still haven't upgraded)

My initial thought is absolute positioning with a top set at 0 and the left set at clientX - the divisions width - 22 with a z-index of a very large number.
0
 
LVL 2

Author Comment

by:khoama
ID: 18784213
The problem is when users scroll down it no longer stay at the top right corner.
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 18784247
Ah... might have something for you.

You'll need to attach an event to the body for onscroll.

say something like:

if (document.body.attachEvent) {
        document.body.attachEvent(onscroll, doScroll);
} else {
      if (document.body.addEventListener) {
              document.body.addEventListener("scroll", doScroll, true);
     }
}

 
var newTop = 0;

function doScroll(e) {
        if (window.screenTop) {
            newTop = window.screenTop;  // IE
      } else {
            try {
                  newTop = (e.screenY) ? e.screenY : 0;  // DOM
            } catch(f) {}      
      }
        document.getElementById('divId').style.top=newTop;
}

0
 
LVL 13

Accepted Solution

by:
Mark_FreeSoftware earned 125 total points
ID: 18786307

take a look at this page:
http://www.cssplay.co.uk/layouts/fixed.html


what gmail does,
is with javascript checking the browser version,
and trough some ajax framework delivers browser specific code
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 18786440
Nice!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tutorial for ebay api 3 80
$q.all is slower or not  in  Angularjs 2 37
Display field if column exists 7 35
form isn't working is it missing a document 21 24
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime is disastrous for companies and can lead to major hits on a brand, reputation, an…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question