Felipe
Felipe

Reputation: 11887

Can I programatically set and/or get the position of the scroll bar in my client's browser?

I have a web site, and I would like to control the scroll bar.

I'd like to be able to say, use a method like scroll_bar_set($height) (if such functions exist)...

I guess it should be javascript or jquery.

Can anybody tell me ?

Thx in advance

Upvotes: 0

Views: 109

Answers (3)

leopic
leopic

Reputation: 3002

I might be too old school, but there is other way you can do it without Javascript.

You can use an tag somewhere in your HTML and link the user to say google.com/#second and the browser will take the user to either an A tag that has it's 'name' attribute with the value of 'second' or to an element whose ID is 'second', in either way it's going to find an unique element with the value of 'second'.

Keep in mind that this might be more accurate than setting a hard vertical position, since unless you have a very anal control over word breaking, line spacing, font easing and others, things are going to shift a few pixels from browser to browser and OS to OS.

Upvotes: 2

Srluisreyes
Srluisreyes

Reputation: 65

If you don't want to add jQuery just for this basic function. Then try using

window.scrollTo(xpos,ypos);

you can put this on a js function like so

function scrollTop(){
   window.scrollTo(0, 0);
}

You can also pass % in to the values window.scrollTo(0,100%);

Upvotes: 1

Emil
Emil

Reputation: 8527

see http://api.jquery.com/scrollTop/ and http://plugins.jquery.com/project/ScrollTo

scrollTop lets you get and set the scroll position.

Upvotes: 1

Related Questions