| | |
Scrollbar help?
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
•
•
I need serious help with Scrollbars. how can i position them so they go exactly where i need them. say on a picture i need it in the circle area how can i get it there and what do i need to do? Could somebody point me in the right direction or towards a tutorial?
Thanks
Do you want to move the scrollbar to a specific position?
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
•
•
picture i need it in the circle area how can i get it there and what do i need to do?
Last edited by katarey; Nov 13th, 2006 at 6:18 pm.
Not sure what you mean by "positioned to go along with the picture. ". I might just be looking at it from the wrong angle..
As for moving the scrollbar, yes you can do it with JavaScript. Its a bit tricky, but not too complicated.
If you're working with a vertical scrollbar, heres the properties of the scrollbar.
Assume you have an element (el) of ID = mydiv.
To change where the scrollbar is you'll just be modifying the scrollTop property of the element (that has the scrollbar you want to move).
Eg:
The scrollTop property shows how many pixels from the top the scrollbar is. So if you want to move it up right to the top, its just el.scrollTop = 0;
However, if you want to move it to the bottom, there is not scrollBottom property, you'll still have to use scrollTop. If you just need it right at the bottom, just make scrollTop an extremely large number like: el.scrollTop = 5000; . That will move it down 5000 px, which is more than any normal screen resolution (I think).
If you want to know specifically how many pixels you are from the bottom, you'll have to use something like:
or you could make it a property of all HTML elements.. so you can use it withought writing all that code over and over..
You'd use it like el.scrollBottom();
(not sure how to set just a regular property).
ref:
http://www.quirksmode.org/js/doctypes.html
http://www.mozilla.org/docs/dom/mozilla/protodoc.html
As for moving the scrollbar, yes you can do it with JavaScript. Its a bit tricky, but not too complicated.
If you're working with a vertical scrollbar, heres the properties of the scrollbar.
Assume you have an element (el) of ID = mydiv.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var el = document.getElementById('mydiv'); // div element var h = el.scrollHeight; // height of div scroll var y = el.scrollTop; // vertical scroll offset from top (of scrollHeight) var c = el.clientHeight; // scroll bar height
To change where the scrollbar is you'll just be modifying the scrollTop property of the element (that has the scrollbar you want to move).
Eg:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
el.scrollTop + 5; // move vertical scroll 5px down el.scrollTop - 5; // move vertical scroll 5px up
The scrollTop property shows how many pixels from the top the scrollbar is. So if you want to move it up right to the top, its just el.scrollTop = 0;
However, if you want to move it to the bottom, there is not scrollBottom property, you'll still have to use scrollTop. If you just need it right at the bottom, just make scrollTop an extremely large number like: el.scrollTop = 5000; . That will move it down 5000 px, which is more than any normal screen resolution (I think).
If you want to know specifically how many pixels you are from the bottom, you'll have to use something like:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var el = document.getElementById('mydiv'); // div element var h = el.scrollHeight; // height of div scroll var y = el.scrollTop; // vertical scroll offset from top (of scrollHeight) var c = el.clientHeight; // scroll bar height var scrollBottom = h - (y + c); // offset of scroll from bottom
or you could make it a property of all HTML elements.. so you can use it withought writing all that code over and over..
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
HTMLElement.prototype.scrollBottom = function() { var el = this; // element var h = el.scrollHeight; // height of element scroll var y = el.scrollTop; // vertical scroll offset from top (of scrollHeight) var c = el.clientHeight; // scroll bar height var scrollBottom = h - (y + c); // offset of scroll from bottom return scrollBottom; }
You'd use it like el.scrollBottom();
(not sure how to set just a regular property).
ref:
http://www.quirksmode.org/js/doctypes.html
http://www.mozilla.org/docs/dom/mozilla/protodoc.html
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
•
•
All of the above post is related to events generated by the scrollbar. They won't help you "position it".
In your example, the image is likely in an IFRAME. The scrollbar is attached to the frame, not the image.
You can create a custom HTML element that looks like and functions like a scrollbar, and place it where ever you want, but it would be a ton of code, if possible...
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
you can use bookmarked anchor tags to position the user's view somewhere. combined with some absolute positioning over the part of your image you want in focus, and a bit of offset calculation (you'll see what I mean if you take the <br/> parts out of the <a> tags), you'll get something like the effect you described...
i've uploaded it so you can see it working:
http://www.fusiongroupuk.com/anchorbouncing/index.html
try:
http://www.fusiongroupuk.com/anchorbouncing/index.html#place1
http://www.fusiongroupuk.com/anchorbouncing/index.html#place2
http://www.fusiongroupuk.com/anchorbouncing/index.html#place3
or click the anchors to bounce about =P
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "<a rel="nofollow" class="t" href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" target="_blank">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</a>"> <html> <head> <title>Anchor Bouncing</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <img src="big_picture.gif" width="100%" height="1000px"/> <a name="place1" style="position:absolute;left:100px;top:50px;" href="#place2"><br/><br/><br/><br/><br/>Place 1 is here</a> <a name="place2" style="position:absolute;top:400px;left:50%;" href="#place3"><br/><br/><br/><br/><br/>Place 2 is here</a> <a name="place3" style="position:absolute;left:50px;top:700px;" href="#place1"><br/><br/><br/><br/><br/>Place 3 is here</a> </body> </html>
i've uploaded it so you can see it working:
http://www.fusiongroupuk.com/anchorbouncing/index.html
try:
http://www.fusiongroupuk.com/anchorbouncing/index.html#place1
http://www.fusiongroupuk.com/anchorbouncing/index.html#place2
http://www.fusiongroupuk.com/anchorbouncing/index.html#place3
or click the anchors to bounce about =P
Last edited by MattEvans; Nov 14th, 2006 at 2:09 am. Reason: , != .
Plato forgot the nullahedron..
![]() |
Similar Threads
- Abnormal Behaviour of Vertical ScrollBar (VB.NET)
- need help making scrollbar (HTML and CSS)
- scrollbar applet (Java)
- Impossible to scroll a richtextbox from a scrollbar (VB.NET)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Link-style
- Next Thread: Does window.stop() work in IE?
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
acid2 ajax ajaxexample ajaxjspservlets array blackjack browser captcha captchaformproblem cart child class close codes date debugger dependent developer disablefirebug dom editor element embed engine enter events explorer ext file firefox flash focus form forms frameworks game getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe java javascript javascripthelp2020 javascripts jquery jsf jsp jump libcurl listbox maps marquee masterpage math media menu object onerror onmouseoutdivproblem onmouseover onreadystatechange parent passing paypal pdf php position post programming prototype rated redirect safari scale scriptlets scroll search security size software sources star starrating stars stretch synchronous toggle tweet unicode variables web webservice window \n







so i cant move it anywhere? then howcome on some web pages they have it positioned to go along with the picture.