Solved

Anchor floating DIV to image

Posted on 2006-11-16
2
601 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

705 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