...

View Full Version : Scrolling Div Vertically to an Element ID



marcus1060
08-01-2008, 10:58 PM
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?

IrDewey
08-01-2008, 11:40 PM
You could use anchors, like so:

Just put something like this in, or around the element:


<a name="name"></a>


and call it like this:


document.location.href = "#name"

Arty Effem
08-02-2008, 12:21 AM
You could use anchors, like so:

Just put something like this in, or around the element:


<a name="name"></a>


and call it like this:


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.

marcus1060
08-02-2008, 04:04 AM
But this is scrolling inside of a div which is set to hide overflow.
That wouldn't work would it?

greasonwolfe
08-02-2008, 05:19 AM
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.

Arty Effem
08-02-2008, 05:25 AM
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 (http://scripterlative.com?softdivscroll) instead.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum