Question about anchors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DogBot
    New Member
    • Sep 2007
    • 11

    Question about anchors

    To define my question I need to establish an example:
    Let's say I have a web page (MYPAGE.HTML) and
    this webpage is constrained in width.
    This web page has 200 lines of text.
    I have an anchor on line 30
    Code:
    <a name="myanchor">
    and a link on the first line that points to that anchor
    Code:
    <a href="#myanchor">go to anchor</a>
    If I click on the link the webpage will scroll up so that line 30
    is now at the top of the browser window.

    Here is the question.
    I do not want line 30 to come to the top of the browser. I want it to come up to
    the middle of the browser page (or any other point lower that the top of the page)
    Say for example 50 pixels from the top.

    I cannot do it by moving the anchor point to another line or adding another anchor point. I must do it using CSS or Javascript or both.

    Don't be concerned about why, please, it will just complicate the question.My biggest problem so far has been explaining the problem!
    But if you must know see this thread

    Thanks
    Last edited by gits; Dec 15 '09, 09:26 AM. Reason: added code tags
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    Try This

    I think this is what you are looking for.

    Thanks and Regards
    Ramanan Kalirajan

    Comment

    • DogBot
      New Member
      • Sep 2007
      • 11

      #3
      Thanks Ramanan, this gives me the basic mechanism for doing this. As far as implementation I suppose I need to somehow dynamically get the current position of all anchors on the page and then programatically change them to that value + 300px(or whatever number I need)

      Having said that I have no idea how one does that...but I will start searching the web for the first part (get the current position of all anchors on the page)
      and go from there.

      Again thanks

      P.D. or maybe an "onclik" command? but this would imply inline JavaScript which i do not want to do to my client..I you have any ideas I'd appreciate them. Thanks

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        P.D. or maybe an "onclik" command? but this would imply inline JavaScript which i do not want to do to my client..
        then use:
        Code:
        Element.onclick = fnName;
        // or
        Element.addEventListener("click", fnName, false); // [I]true[/I] if you want to capture the event

        Comment

        Working...