Solved

How to make a div that always stay on top

Posted on 2007-03-23
5
4,926 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
Comment Utility
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
Comment Utility
The problem is when users scroll down it no longer stay at the top right corner.
0
 
LVL 29

Expert Comment

by:rdivilbiss
Comment Utility
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
Comment Utility

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
Comment Utility
Nice!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now