Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Aug 2005
    Location
    Canada
    Posts
    137
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Scrolling Div Vertically to an Element ID

    I have a div that I'm using some Javascript scroll a certain amount of pixels when a button is clicked, I'd also like to have it so that when another link is clicked it can scroll automatically to an element with a specified ID.

    Anyone have any idea on how to do this?

  • #2
    New Coder
    Join Date
    Jul 2008
    Posts
    10
    Thanks
    0
    Thanked 1 Time in 1 Post
    You could use anchors, like so:

    Just put something like this in, or around the element:
    Code:
    <a name="name"></a>
    and call it like this:
    Code:
    document.location.href = "#name"

  • #3
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by IrDewey View Post
    You could use anchors, like so:

    Just put something like this in, or around the element:
    Code:
    <a name="name"></a>
    and call it like this:
    Code:
    document.location.href = "#name"
    Actually element IDs can be specified as anchors, so there's no need to surround an element with an <a> tag.

  • #4
    Regular Coder
    Join Date
    Aug 2005
    Location
    Canada
    Posts
    137
    Thanks
    2
    Thanked 0 Times in 0 Posts
    But this is scrolling inside of a div which is set to hide overflow.
    That wouldn't work would it?

  • #5
    Regular Coder
    Join Date
    Nov 2004
    Location
    near the only active volcano in the continental US
    Posts
    409
    Thanks
    6
    Thanked 2 Times in 2 Posts
    You can probably use the same script that is scrolling based on the button click. Turn the link into a <span> element with an onClick event that calls the same function the button is calling. All you would need then is to know the pixel location of the element you want to scroll to.

    Post the coding you have and we might be better able to help you with this.
    Greason Wolfe
    +++++++++++
    Sometimes you don't know what you know until you know it.

  • #6
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by marcus1060 View Post
    But this is scrolling inside of a div which is set to hide overflow.
    That wouldn't work would it?
    Yes it will, and you can gentrify the operation by using SoftDivScroll instead.


  •  

    Posting Permissions

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