Solved

Anchor floating DIV to image

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now