vForums Support Banner



 

Welcome Guest! Please Login or Register
vForums Support :: Programming & Coding :: Programming Discussion :: scroll() - View Topic
Topic Rating: *****
Printable View
Marc
vChat Developer
*****
I <3 Rossy

Posts: 3,388
Status: Offline
Gender: Male
Location: Ontario, Canada
Age: 32
Joined:  

Additional Groups:
Coding Team
***


Reputation: 40%  


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]
Recoding the future

Posts: 4,043
Status: Offline
Gender: Male
Location: UK
Joined:  

Additional Groups:
Coding Team
***


Reputation: 58%  


pmtwittervForum
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]

Posts: 3,709
Status: Offline
Gender: Male
Age: 9 14
Joined:  

Additional Groups:
Support Team
***


Reputation: 45%  


pmwwwtwittergtalkvForum
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
 
  1. function get_position(id) {
  2. var top = 0;
  3. var left = 0;
  4. var obj = document.getElementById(id);
  5. if (obj.offsetParent) {
  6. left = obj.offsetLeft;
  7. top = obj.offsetTop;
  8. while (obj = obj.offsetParent) {
  9. left += obj.offsetLeft;
  10. top += obj.offsetTop;
  11. }
  12. }
  13. return Array(top, left);
  14. }
 



Edit: Reading Wrightys reply it looks like we're both thinking of different things {Unsure}

Image
Marc
vChat Developer
*****
I <3 Rossy

Posts: 3,388
Status: Offline
Gender: Male
Location: Ontario, Canada
Age: 32
Joined:  

Additional Groups:
Coding Team
***


Reputation: 40%  


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. {Wink}

rroll.to— Shorten a link, rickroll your friends.
Simie
New Member
*

Posts: 20
Status: Offline
Joined:  
Reputation: 0%  


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;


{Smile}
Marc
vChat Developer
*****
I <3 Rossy

Posts: 3,388
Status: Offline
Gender: Male
Location: Ontario, Canada
Age: 32
Joined:  

Additional Groups:
Coding Team
***


Reputation: 40%  


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;


{Smile}


Knew there was a way to do it; I'll try it in a sec. {Smile}

Yay, it works! {Grin}

Thanks Simie. {Smile} Smiley

rroll.to— Shorten a link, rickroll your friends.
Simie
New Member
*

Posts: 20
Status: Offline
Joined:  
Reputation: 0%  


pm
Re: scroll() (3rd Mar 08 at 8:50pm UTC)
No problem {Smile}

Btw:
Error: x is not a function
Source File: http://www.cr0wonline.com/_/scrollDiv.php
Line: 1

{Sad}
Michael
Moderator
*****

[Avatar]
Recoding the future

Posts: 4,043
Status: Offline
Gender: Male
Location: UK
Joined:  

Additional Groups:
Coding Team
***


Reputation: 58%  


pmtwittervForum
Re: scroll() (3rd Mar 08 at 8:52pm UTC)
Neither is y! {Sad}
Marc
vChat Developer
*****
I <3 Rossy

Posts: 3,388
Status: Offline
Gender: Male
Location: Ontario, Canada
Age: 32
Joined:  

Additional Groups:
Coding Team
***


Reputation: 40%  


pmwww
Re: scroll() (3rd Mar 08 at 8:57pm UTC)
I was testing some stuff. {Tongue Out}

rroll.to— Shorten a link, rickroll your friends.
Simie
New Member
*

Posts: 20
Status: Offline
Joined:  
Reputation: 0%  


pm
Re: scroll() (3rd Mar 08 at 8:58pm UTC)
Glad to know it worked {Smile}
Marc
vChat Developer
*****
I <3 Rossy

Posts: 3,388
Status: Offline
Gender: Male
Location: Ontario, Canada
Age: 32
Joined:  

Additional Groups:
Coding Team
***


Reputation: 40%  


pmwww
Re: scroll() (3rd Mar 08 at 9:02pm UTC)
 
Glad to know it worked {Smile}


Thanks for the help. {Smile}

*Heads outside*

rroll.to— Shorten a link, rickroll your friends.
 Printable View

All times are GMT+0 :: The current time is 3:41pm
Page generated in 5.7301 seconds
This Forum is Powered By vForums (v2.4)
Create a Forum for Free | Find Forums