Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Layer Position 1

Status
Not open for further replies.

fischadler

Programmer
May 31, 2002
258
MT
The code below puts a layer at the top left corner of my page (when set to visible).

Code:
<div style="position: absolute; visibility:hidden" id="myLayer">
<img src="somepicture.jpg">
</div>

How can I adjust it so that the layer comes up at the top left corner of the browser window rather than the page? That way, no matter how much I scroll down, the layer still is visible. I have a long list with each row having a picture with an onclick command to make the layer visible.

Thanks

"Facts Are Meaningless - They Can Be Used To Prove Anything" - Homer Simpson
 
If it's just a picture, you could use this:
Code:
<style>
BODY
{
  background-image: url(image.jpg);
  background-attachment: fixed;
  background-position: left top;
  background-repeat: no-repeat;
}
</style>
Otherwise, check out faq216-4076

Adam
 
I have a list of rows retrieved from a database with a delete button on the right side of each row.
What I'm trying to do is to mimic a yes-no message box that should appear in the center of the user's screen so that the user can confirm whether the record really needs to be deleted. If they choose "no" the layer simply disappears.
So far, the closest I got was to get the message box in the same level as the button pressed. But it's always a fixed distance from the left side. That's OK since the table does not scroll left and right.

"Facts Are Meaningless - They Can Be Used To Prove Anything" - Homer Simpson
 
For non-IE:
Code:
position: fixed;

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
Thanks Chessbot. However, most of the users of the page will have IE. What would really help me now is a function that returns the distance, in pixels, from the top of the page to the top of the visible area the user has scrolled to.

"Facts Are Meaningless - They Can Be Used To Prove Anything" - Homer Simpson
 
Like this?
Code:
function getTop(){
  return document.body.scrollTop
}

Adam
 
That's it!! Thanks very much!

Is it possible to determine the size of the browser window?

"Facts Are Meaningless - They Can Be Used To Prove Anything" - Homer Simpson
 
kaht said:
0.08 seconds to be exact adam
Cool, you must be very fast! Did it also take you 0.08 seconds to sift through the loads of information and find the relevant line?

Note that most Java Script newbies like me are not as script knowledgable as you are.

"Facts Are Meaningless - They Can Be Used To Prove Anything" - Homer Simpson
 
fischadler, a well known utility of google is the report listed at the top of each search that tells you how long it took for the google servers to find matches to your query. When I followed the link that adam so gratiously provided for you it gave me a search time of 0.08 seconds. When I made the commet above it was meant to be a joke between adam and I, hence the reason I put his name at the end of the line. You took it completely out of context if you found it offensive.

On a side note, I've been using javascript for little over a year now and when I was a "newbie" I learned almost everything that I know from google. A well worded search on google would have easily answered all your questions above.

-kaht
 
OK, sorry Kaht - I believe I over reacted. As a matter of fact, Adam's link did point me to the right direction. So thanks again Adam.

I had already done some research before posting my question but every time I was directed to very complex code to do what Adam's code did in just one line. So I was hoping he had a similarly easy solution for the second problem. I had also made some searches through the Javascript forum but probably I was not putting in the right search words.

-Fischadler

"Facts Are Meaningless - They Can Be Used To Prove Anything" - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top