?
Solved

Anchor floating DIV to image

Posted on 2006-11-16
2
Medium Priority
?
605 Views
Last Modified: 2010-05-18
I have a div that needs to be anchored to a table that is centered on the page.  The problem is that if the user resizes its browser window, the table moves but not the div. Can anyone help me anchor the div to the table?

<div align="center">
      <table border="1" width="100" height="248" id="table1">
            <tr>
                  <td align="center">table
                                                               <div style="position: absolute; width: 231px; height: 29px; z-index: 1; left: 579px; top: 24px" id="layer1">
                        This Div should anchor as the table moves</div>
                  </td>
            </tr>
      </table>
</div>
0
Comment
Question by:frankmorrison
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 2000 total points
ID: 17961354
Check this:


<body onResize="rePosit()" onScroll="rePosit()" onLoad="rePosit()">
<div align="center">
     <table border="1" width="100" height="248" id="table1">
          <tr>
               <td align="center" id="theAnchor">table
                                                               <div style="position: absolute; width: 231px; height: 29px; z-index: 1; left: 579px; top: 24px" id="layer1">
                    This Div should anchor as the table moves</div>
               </td>
          </tr>
     </table>
</div>

</div>

<script>
function rePosit(){
  var x = y = 0;
  var theCell = document.getElementById("theAnchor");
  while(theCell.offsetParent){
    x += theCell.offsetLeft;
    y += theCell.offsetTop;
    theCell = theCell.offsetParent;
  }
  var theDiv = document.getElementById("layer1");
  theDiv.style.left = x;
  theDiv.style.top = y;
}
</script>

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17963277
You are welcome ;-)
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

800 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