Connecting Tech Pros Worldwide Forums | Help | Site Map

Positioning anchor/cell contents within a scrollable div

Member
 
Join Date: Feb 2008
Posts: 123
#1: Mar 3 '08
Hi all,

This is a pretty simple question, but after some hunting on the web I can't find the answer:

I have a table embedded in a scrollable div, and have each cell anchored so that when a click on a button in another table, the div is scrolled to the corresponding cell of the first table. However, it is positioned such that the cell's contents start at the top-left of the window.

Can I add code which centers the contents of the cell/anchor in the middle of the window of the scrollable div?

Thanks!

Member
 
Join Date: Dec 2006
Location: United States
Posts: 43
#2: Mar 4 '08

re: Positioning anchor/cell contents within a scrollable div


Could you post some of the code you currently have on your page? This will help me determine what changes to make.

Thanks.
Member
 
Join Date: Feb 2008
Posts: 123
#3: Mar 4 '08

re: Positioning anchor/cell contents within a scrollable div


Thanks johnjohn! Below is what I think is all the salient code:

Expand|Select|Wrap|Line Numbers
  1. #holderdiv {
  2. width: 170px;
  3. height: 110px;
  4. overflow: scroll;
  5. border: 1px solid black;
  6. }
  7.  
  8. function go(loc) {
  9. i = parseInt(loc.substr(5));
  10. window.location.href = loc;
  11. }
  12.  
  13.  
  14.       <td><input name="pos" onclick="go('#cell1');"
  15.  type="radio"></td>
  16.  
  17. <div id="holderdiv"> 
  18. <table style="text-align: center; width: 1700px" id="table1"
  19.  border="1" cellpadding="0" cellspacing="0">
  20.   <tbody>
  21.     <tr>
  22.       <td style="width: 150px; height: 100px;"><div style="position: relative;" id="cell1">A1<br>
  23. Empty</td>
  24.       <td style="width: 150px; height: 100px;"><div style="position: relative;" id="cell2">A2<br>
  25. Empty</td>
  26. </div>
  27.  
Member
 
Join Date: Feb 2008
Posts: 123
#4: Mar 5 '08

re: Positioning anchor/cell contents within a scrollable div


Hi again!

Just seeing if anyone has a suggestion.

Thanks!
rnd me's Avatar
Expert
 
Join Date: Jun 2007
Location: Urbana IL
Posts: 411
#5: Mar 8 '08

re: Positioning anchor/cell contents within a scrollable div


the cell's offsetTop and offsetLeft properties are what you need.
Member
 
Join Date: Feb 2008
Posts: 123
#6: Mar 8 '08

re: Positioning anchor/cell contents within a scrollable div


Hi johnjohn+rndme,

Thanks for the reply.

I actually ended up using mootools to do it in JS. It adds a nice sliding effect too!
Reply