Solved

Anchor floating DIV to image

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

733 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