Marc vChat Developer
     I <3 Rossy
Posts: 3,388 Status: Offline Gender: Male Location: Ontario, Canada Age: 32 Joined:
Additional Groups: Coding Team
  
pmwww | scroll() (1st Mar 08 at 12:24am UTC) | | 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. | |
rroll.to— Shorten a link, rickroll your friends. |
|
Michael Moderator
    
![[Avatar]](http://av.wservices.co.uk/av.png) Recoding the future Posts: 4,043 Status: Offline Gender: Male Location: UK Joined:
Additional Groups: Coding Team
  
pmvForum | Re: scroll() (1st Mar 08 at 12:30am UTC) | | have you tried:
document.getElementById('x').scroll(x,y);
*hasn't tried it* | |
|
Ross Administrator
    
![[Avatar]](http://uploads.virtualforums.co.uk/forums/pokemon/vforums-qr1.png) Posts: 3,709 Status: Offline Gender: Male Age: 9 1⁄4 Joined:
Additional Groups: Support Team
  
pmwwwgtalkvForum | Re: scroll() (1st Mar 08 at 12:32am UTC) | | 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 | |
|
|
Marc vChat Developer
     I <3 Rossy
Posts: 3,388 Status: Offline Gender: Male Location: Ontario, Canada Age: 32 Joined:
Additional Groups: Coding Team
  
pmwww | Re: scroll() (1st Mar 08 at 12:39am UTC) | | @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. | |
rroll.to— Shorten a link, rickroll your friends. |
|
Simie New Member

Posts: 20 Status: Offline Joined:
pm | Re: scroll() (3rd Mar 08 at 8:31pm UTC) | | 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;
| |
|
Marc vChat Developer
     I <3 Rossy
Posts: 3,388 Status: Offline Gender: Male Location: Ontario, Canada Age: 32 Joined:
Additional Groups: Coding Team
  
pmwww | Re: scroll() (3rd Mar 08 at 8:33pm UTC) | | 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.  | |
rroll.to— Shorten a link, rickroll your friends. |
|
Simie New Member

Posts: 20 Status: Offline Joined:
pm | |
Michael Moderator
    
![[Avatar]](http://av.wservices.co.uk/av.png) Recoding the future Posts: 4,043 Status: Offline Gender: Male Location: UK Joined:
Additional Groups: Coding Team
  
pmvForum | Re: scroll() (3rd Mar 08 at 8:52pm UTC) | | Neither is y! | |
|
Marc vChat Developer
     I <3 Rossy
Posts: 3,388 Status: Offline Gender: Male Location: Ontario, Canada Age: 32 Joined:
Additional Groups: Coding Team
  
pmwww | Re: scroll() (3rd Mar 08 at 8:57pm UTC) | | I was testing some stuff. | |
rroll.to— Shorten a link, rickroll your friends. |
|
Simie New Member

Posts: 20 Status: Offline Joined:
pm | Re: scroll() (3rd Mar 08 at 8:58pm UTC) | | Glad to know it worked | |
|
Marc vChat Developer
     I <3 Rossy
Posts: 3,388 Status: Offline Gender: Male Location: Ontario, Canada Age: 32 Joined:
Additional Groups: Coding Team
  
pmwww | Re: scroll() (3rd Mar 08 at 9:02pm UTC) | | Glad to know it worked
Thanks for the help.
*Heads outside* | |
rroll.to— Shorten a link, rickroll your friends. |
|