Results 1 to 9 of 9

Thread: Anchor links

  1. #1
    Join Date
    May 2008
    Posts
    144
    Thanks
    6
    Thanked 11 Times in 11 Posts

    Default Anchor links

    how do i make these scroll smoothly instead of "jumping" to the anchor... also, how do i jump to a DIV using the ID in IE?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That's really two separate questions. As to the first, you would need javascript, Google:

    Smooth Scroll

    As to the second, just put an named anchor link in it instead. But if you must use id, you could use a javascript method for that:

    Code:
    document.getElementById('id').scrollIntoView();
    But it wouldn't be any smoother than a named anchor jump, and only active if the user had javascript enabled.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    thenajsays (05-16-2008)

  4. #3
    Join Date
    May 2008
    Posts
    144
    Thanks
    6
    Thanked 11 Times in 11 Posts

    Default

    Thank you so much... one more thing... im very very new to javascript... how/where would i add the "document.getElementByID" code?

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    There are many places you could use such a code snippet. One would be with a link like:

    HTML Code:
    <a href="#foot" 
    onclick="document.getElementById('footer').scrollIntoView();return false;"
    >Credits</a>
    that would be somewhere far enough above an element like:

    HTML Code:
    <div id="footer"><a name="foot"></a>
    Brought to you by your friends at this web site.
    </div>
    so that the footer element wouldn't already be in view. The named anchor would act as a non-javascript fall-back.

    But let me be clear. This will not scroll smoothly to the element, all it really does is avoids having #foot appended to the URL, and in some browsers will avoid the click noise usually associated with a link being clicked, and it will prevent a change in the load status of the page for those browsers that might execute one with a named anchor. But only when javascript is enabled.

    For smooth scrolling you would need more elaborate code, which I already gave you a hint on how to find using Google.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #5
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    in the anchor tag

    Code:
    <a href="#idToGetTo" onclick="javascript:document.getElementById('idToGetTo').scrollIntoView()">TITLE</a>
    I am declaring it this way, because if the user doesn't have javascript enabled, they will still be able to get to the anchor, however those that do have javascript enabled, will get the transitional affect...

    not sure if you are aware of the term, but its called backwards compatibility

  7. #6
    Join Date
    May 2008
    Posts
    144
    Thanks
    6
    Thanked 11 Times in 11 Posts

    Default

    that worked like a charm...
    i tried smooth scroll but it didnt work... i forgot to mention the site is horizontal scrolling

  8. #7
    Join Date
    May 2008
    Posts
    144
    Thanks
    6
    Thanked 11 Times in 11 Posts

    Default

    i have the site up here (http://www.equusdev.com)

  9. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by boogyman View Post
    in the anchor tag

    Code:
    <a href="#idToGetTo" onclick="javascript:document.getElementById('idToGetTo').scrollIntoView()">TITLE</a>
    I am declaring it this way, because if the user doesn't have javascript enabled, they will still be able to get to the anchor, however those that do have javascript enabled, will get the transitional affect...

    not sure if you are aware of the term, but its called backwards compatibility
    You will almost, probably never target the position an element by its id on a page without javascript. You can target a named anchor (the a tag) though. People often get the two confused - names and ids. Some browsers may use them interchangeably in some cases, but when they do, it's non-standard.

    Scripts that scroll to elements by their id are all fine and good as far as they go. But unless there is a named anchor referenced in the href, there will be no reliable non-javascript fall back.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by heybabylover View Post
    May i have a personal question? counld u sent me your email address?My email is [email link removed], thx, man.
    You really don't want to post your email address in open forum. The spam bots will have you for dinner.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •