Solved

Anchor floating DIV to image

Posted on 2006-11-16
2
598 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
  • 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

810 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