Now, I know that in JS you can use scroll(x,y) to scroll to a specific xy coordinate on the page. But, is there a way to scroll to a specific coordinate within a div, or td, or something similar?
I've been reading up on it lately, but haven't been able to find an answer.
have you tried:
document.getElementById('x').scroll(x,y);
*hasn't tried it*
You'd have to find the position of the div/td first and then add that to the coordinates you want to go to. Take the get_position function I use as an example of how to get that:
Code: JavaScript
- function get_position(id) {
- var top = 0;
- var left = 0;
- var obj = document.getElementById(id);
- if (obj.offsetParent) {
- left = obj.offsetLeft;
- top = obj.offsetTop;
- while (obj = obj.offsetParent) {
- left += obj.offsetLeft;
- top += obj.offsetTop;
- }
- }
- return Array(top, left);
- }
Edit: Reading Wrightys reply it looks like we're both thinking of different things![]()
@Wrighty: I've tried that, no avail.
@Ross: I mean if I have a div with the overflow set to scroll, how can I make that scroll to a certain coordinate rather than the whole page.![]()
I remembered looking at Panic: Coda's site a few weeks ago, and they use a scrolling div.
From what they use, try this:
element.scrollTop = amount;
element.scrollLeft = amount;
![]()
I remembered looking at Panic: Coda's site a few weeks ago, and they use a scrolling div.
From what they use, try this:
element.scrollTop = amount;
element.scrollLeft = amount;
![]()
Knew there was a way to do it; I'll try it in a sec.![]()
Yay, it works!![]()
Thanks Simie.![]()
No problem![]()
Btw:
Error: x is not a function
Source File: http://www.cr0wonline.com/_/scrollDiv.php
Line: 1
![]()
Neither is y!![]()
I was testing some stuff.![]()
Glad to know it worked![]()
Glad to know it worked![]()
Thanks for the help.![]()
*Heads outside*