Positioning anchor/cell contents within a scrollable div

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phub11
    New Member
    • Feb 2008
    • 127

    Positioning anchor/cell contents within a scrollable div

    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!
  • johnhjohn
    New Member
    • Dec 2006
    • 43

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

    Thanks.

    Comment

    • phub11
      New Member
      • Feb 2008
      • 127

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

      Code:
      #holderdiv {
      width: 170px;
      height: 110px;
      overflow: scroll;
      border: 1px solid black;
      }
      
      function go(loc) {
      i = parseInt(loc.substr(5));
      window.location.href = loc;
      }
      
      
            <td><input name="pos" onclick="go('#cell1');"
       type="radio"></td>
      
      <div id="holderdiv"> 
      <table style="text-align: center; width: 1700px" id="table1"
       border="1" cellpadding="0" cellspacing="0">
        <tbody>
          <tr>
            <td style="width: 150px; height: 100px;"><div style="position: relative;" id="cell1">A1<br>
      Empty</td>
            <td style="width: 150px; height: 100px;"><div style="position: relative;" id="cell2">A2<br>
      Empty</td>
      </div>

      Comment

      • phub11
        New Member
        • Feb 2008
        • 127

        #4
        Hi again!

        Just seeing if anyone has a suggestion.

        Thanks!

        Comment

        • rnd me
          Recognized Expert Contributor
          • Jun 2007
          • 427

          #5
          the cell's offsetTop and offsetLeft properties are what you need.

          Comment

          • phub11
            New Member
            • Feb 2008
            • 127

            #6
            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!

            Comment

            Working...