javascript scrollbar

description:

This si some solution how to use javascript scrollbar which you can decorate how you want.
To use it, you have to link css and javascript files.
Then declare 2 divs in your html document calld “scrollholder” and “scroll and place your content.
After declarating these 2 divs you will need to load javascript scrollbar for these div’s.
You will do this by placeing a piece of javascript calling ScrollLoad() function.


You can also set your own sizes and colors for scrollholder and scroll divs.
To do this, use your own class, i recommend you not to style div by using identificator “#scrollholder”, rather use “.yourOwnClassName”.

files

  1. javascript file
  2. css file

parameters:

ScrollLoad ("scrollholder", "scroll", "1", true);

  1. means id of div where scrolling text id holded
  2. means id of div where is declarated content which you want to scroll
  3. means number of scrolling object (in javascript)
  4. menas if scroll tracker will calculate its size or not

features:

  • mouse wheele scrolling
  • automatic creating scrollbar by javascript – so if anyone dont have for some reason enabled javascript, he will be still able to scroll by default scrollbar (you can decorate it too)

css bug:

by using this i have found some css bug in opera with overflow (to see it just save example page and remove css declaration for #operaBug), so to solve this problem you need to put scroll divs to some another element (f.e. div again) and set to it css overflow: hidden;

Example

example page with javascript scrollbar

used on page

I’ve used it on several pages i’ve made, f.e.:

using:

<head>
...
<link rel="stylesheet" type="text/css" href="css/scroll.css" mce_href="css/scroll.css" media="screen,projection"/>
<script type="text/javascript" language="JavaScript" src="js/scroll.js" mce_src="js/scroll.js"></script>
...
</head>

first scrollbar

<body>
...
<div id="scrollholder" class="scrollholder">
<div id="scroll" class="scroll">
... place your scrolling content here ...
</div>
</div>
<script type="text/javascript">
<!--
ScrollLoad ("scrollholder", "scroll", true);
//-->
</script>
...
</body>

second and other scrollbars

...
<div id="scrollholder2" class="scrollholder">
<div id="scroll2" class="scroll">
... place your scrolling content here ...
</div>
</div>
<script type="text/javascript">
<!--
ScrollLoad ("scrollholder2", "scroll2", false);
//-->
</script>
...

features:

If in some reason is javascript disabled, it will show normal scrollbar which you can style. Firefox doesn’t support this.
I had some problems with some older version of browsers, so i preffer to set scrollbar style right to scroll element, even though its not so nice.


/* This property describes the color of the outer top and left bevel edges (the normally lighter portion of the "highlights") of the scrollbar arrows and scroll bar slider box portions of a scroll bar */
scrollbar-3dlight-color: #000000;
/* This property describes the color of the scrollbar directional arrows of a scroll bar when they are activate-able. When scrllbars appear but are not usable, this property does not control the arrow color in this state */
scrollbar-arrow-color:#999999;
/* This property describes the color of the outer bottom and right bevel edges (the normally darker portion of the "shadows") of the scrollbar arrows and scroll bar slider box portions of a scroll bar */
scrollbar-darkshadow-color:#ff0000;
/* This property describes the color for the button face of the scrollbar arrow widgets, the button face color of the slider widget and the main color of the inactive square at the bottom/right corner of the scrolled box. This property has no effect on the scrollbar tray/track that the scrollbar slider widget travels in */
scrollbar-face-color:#00ff00;
/* This property describes the color of the inner top and left bevel edges (the normally darker portion of the "highlights") of the scrollbar arrows, the scroll bar slider box, and half of the dither pattern color of the scrollbar slider tray area (the other half of the dither is taken from the OS default button face color.) */
scrollbar-highlight-color:#0000ff;
/* This property describes the color of the inner bottom and right bevel edges (the normally lighter portion of the "shadows") of the scrollbar arrows and scroll bar slider box portions of a scroll bar */
scrollbar-shadow-color:#666666;
/* This property describes the solid color of the scrollbar track */
scrollbar-track-color:#ffffff;

known problems:

scrolling by mouse wheele its also scrolling all page, not just the content you want.

terms of use:

there WAS just one, if you want to use this scrollbar includ back link to http://www.webdesigners.sk on every page where is this scorllbar used or just on your home page.

now, if you wamt to support me, you can also donate. amount is up to you :)

Tags: ,

good post.
BUG: when i contein scrollholder in tag TD, script d`t work

hi
i dont use tables to design pages so i didn’t detect this problem.
pls post here or send by email link to some example page where you got problem with it and i ll look at it.

Hi I had the same problem so I put the javascript reference just before the tag and that solved it. Thanks Gondo. Site still designign so no url yet.

very interesting.
i’m adding in RSS Reader

Hi
its nice implementation. Can’t we make it look similar to scrollbar by putting up arrow and down arrow images? and on click of up and down to make it scroll slowly instead of coming down suddenly?

Thanks

hi
at start i was thinking about arrows, but than i choose not to use tham cause i think its useless. but i am thinking about new version where ll be also horizontal scrolllbar, and ll be not needed any special elements, just a content in 1 element (f.e. in div) and it ll be calld by setting some class (f.e. <div class=”scroll”>here ll be content</div>)
and if there is interest as i see, i ll do there arrows too.
but i ll have to find some time to do it :)
so time to time have a look here, and if u like (or not), “look” at adds :)

This is a great javascript use. Can this be modified to do horizontal scrolling? If so how?

hi
hm this one no, but as i mentioned before, i ll make new one which ll be also hotizontal.
anyway, if any1 is interesting, i made horizontal scroll for this site creeo.net so u can inspire there till i ll bring that new one.

Is there a way to turn off the scrollbar? I want it to appear just sometimes, and I was wondering if there was a way to turn it off so I can turn it on again later on.

hi
fuu not now :( its first time i hear that some1 wana do this.
but i ll think about it .

I’m using this on a drop down list… and I want it to appear just some of the times. The problem being that if I use ScrollLoad() several times that’ll just create a new scroll each time, next to any other that has been already created.

I’m thinking of a implementing a function that deletes div trackn (n being the number of the last div track implemented)… I’ll let you know how it goes.

Hm yeah, I’m keeping a counter for n and delete with removeChild… that way I can keep creating new scrollers without them appearing next to the already created ones.

You might want to implement a function to remove the scroll from the page just so it is complete.

Kudos to you for this, however, it’s the easiest scroller to implement that I’ve found online :)

Is there a way to re-init a existing scrollbar? i want to resize the scrollbar when i resize the browser-window.

its not implemented now, but its possible to done that by removing (not implemented yet too) scroll, changing object size and re-load scroller.
but ll think about it in next generation.

gondo, thank you very much for this script. best on the internet!

Please do implement a “re-init” function. I would be very happy if you could do that.

Hi!

Thanx for this nice script!
Just want to know if there is a possibility to speed up the ScrollWheel scrolling? Now I have to scroll 3 times for 2-3 lines…

Thanx!!!

Ok – got it – dw_scrollObj.speed

Hails!
I’ve just discovered one more bug if I am not mistaken….
here it is:
http://www.dvgcasino.com/vip (fuck – don’t think it’s an ad..ha haa=)))
when you FIRST TIME open the page the scroll CUTS scrolling content’s bottom….but simple PAGE REFRESH solves the problem. Any ideas why is it so? This happens both with FF and IE.

Is there a more comprehensive tutorial on how to implement this script? I am having some problems getting it to work properly. Also is there a way to increase the width of the text field?

Thanks

Great looking script

Wanted to add some. It shows with the regular style scroll bar. Also is there a way to increase the height a little.

>BUG: when i contein scrollholder in tag TD, script d`t work

You can use :

setTimeout( ‘ScrollLoad ( “scrollholder”, “scroll” , true);’ , 1 )

to remove the Scroll Bar :

dw_scrollObj.prototype.removeBar = function() {
var bar;
var lyr = document.getElementById(this.lyrId);
var wn = document.getElementById(this.id);
if (this.vBarId) {
bar = document.getElementById(this.vBarId);
dom_removeObj(bar.parentNode)
}
if (this.hBarId) {
bar = document.getElementById(this.hBarId);
dom_removeObj(bar.parentNode)
}
}

I had a parameter “No” to the following function :
function ScrollLoad (Area, Content, SettingTracSize , No)
{
if (typeof No == “undefined”){No=document.No ; document.No++;}
var code = “scroller” + No + ” = new dw_scrollObj (Area, Content, Content, Area, No);”;

if (SettingTracSize)
code += “scroller” + No + “.setBarSize();”;
eval (code);
makeMouseWheeleScrolling(Area);
}

then you can use :
scroller0.removeBar();
ScrollLoad ( “scrollholder” , “scroll” , true , 0 );

Hope this help …

miron: hmm i was checking it (different versions: opera, ff, ie) but did not seen any cutting, or any change after refresh, pls send some screenshots if its possible.

lost: i dont think u ll find “more comprehensive tutorial” simply because this one is sufficient. width and height (also other style) are defined in css files. pls describe your problem little bit more or send me link to some page where you tried to implement it.

witty: thx on first look it looks good.
note to problem woth TD or tables at all.
there is problem cause tables are show aggregate (thats why tables were used as style layout in the past – the whole page shows at once) so javascript can’t change table parts until the table is not completely loaded.

Gondo:

Thanks for your reply. I would have posted sooner but I had to tidy up somethings. For some reason I assumed the width/height couldn’t be that easy to do, so I didn’t look at the CSS *smacks forehead*.

I am still having difficulty getting the scroll bar to display properly. It works but it shows up as a normal scroll bar.

Here’s the site it is being used on. This is a test page and it hasn’t been finished.

5point website

Thanks again – ps there will be a link back to you from the home page

http://www.5point.com/mercier/mercier.html

sorry for some reason the link didn’t work

Hi gondo…

i have a big problem: scroll dosn’t work on SAFARI on MAC… any solutions?

lost: ehm :) you dont have loaded scroll.js correctly, check its possition on server, try to write there alert(‘live’) to see if u loaded it irght.

Stefano: its possible, i dont have mac at home, so i can’t test it right now. but i ll try to do it. ty for reply.

thanks a lot… i wait for your reply because i have loaded correctly scroll.js…

you can try also with SAFARI on windows because the problem is also there.

if you refresh page a couple of time scroll disappear or scroll will be blocked…

however i wait for your help for safari on mac :-(

thanks a lot for your time and great job

stefano

any news ? :-/

Hey gondo, thanks a lot for this script, it truly is the easiest scrollbar ive ever implemented.

I’m having an issue however. Rather than have a rectangle for the scrollbar, i wanted a circle. What I was going to do was use a .gif of a blue circle as the background color for drag_bar in CSS and set it to no-repeat. This works and looks fine, but the dragbar is still a large size and thus it seems as if i cant scroll down to the bottom edges. How do change the size of the scrollbar to something smaller? Anything simple? What would i need to fiddle with? Thanks

Stefano,
Did you found any sollution yet? I’m having the same problem. The strange thing is that I don’t have this problem always :-s

For the rest: this is a wonderful script ! Tnx Gondo !

any solutions :-( …

Hi Gondo!
very nice script :)

I tried to use html-anchors to jump to several places inside the scrollable content. In this case, the drag_bar will not actualise his position automatically and ‘jump’ out of sight :(

Is there any chance to let the drag_bar know that the content of the scrolling area is already scrolled and recalculate the position of the drag_bar?

Thx for Your work, well done :)

Hi,

which function do I have to call when the height of the scrollelement

changes … (a hidden child div that becomes visible)

Stefano,

I solved the problem by including the script higher in the script. Now it loads in the beginning and this solved my problem.

hi jorg. How do you have solved? i don’t understand…

I call the script as high as possible in the header of my html doc and place the

in another div with a fixed height.

I call the script as high as possible in the header of my html doc and place the
div (id=”scrollholder” class=”scrollholder” id=”scroll” class=”scroll”) AND div (id=”scroll” class=”scroll”)
in another div with a fixed height.

hi,
I have a problem. I want the slider [drag_bar] to be a picture and it’s size to be dynamic. The problem is that i don’t know of a way to strach that background-image. In CSS3 yes, but it has not appeard yet. If you know of a way please tell me. My solution was to put tag instead of the div with the class name “drag_bar”. It works but not 100%. I cannot drag the image, only for a few pixels. And when I release the mouse the image is sticked to the movement of the mouse. When I click again the slider is no longer sticked. Can you tell me a solution to either of the issues?
Thanx,
Janus

Hey gondo
i m going to post some musical scrap script on my blog site
But when i post the scrap script it will run on my blogsite. & i want to show the script to visitors plz help me
if u want to know which type of scrollbox i want plz go to:http://musicalscraps.blogspot.com & give me the trick on my id at goodboy_shrikant@yahoo.com otherwise post hear please…………………,

does this work in any browser?.like in firefox?.

Hey,
I’m working on a site right now, and the scroll speed is really slow. How do I speed that up? I saw someone else’s post about this but I needed more information.

I have a problem. How to use javascript to control the scrollbar scroll down? I want to scroll it to the bottom automatically after it load.

Can you please make it with arrows?? Thanx!

hey what’s up, nice script gondo,I wanted to ask you would you please upload the horizontal script I would love to use it.
thanks a lot

miron: hmm i was checking it (different versions: opera, ff, ie) but did not seen any cutting, or any change after refresh, pls send some screenshots if its possible.

RE: same thing happen to me here is a screenshot

http://www.ebalay.com/diego/scrollfirsttime.gif

http://www.ebalay.com/diego/scrollafterrefresh.gif

Gondo:

Thank you very very much for writing this script. It saved me an immense amount of time, and the functionality fits all of my needs. Kudos to writing a fast script as well!

Thanks again.

Ryan Lane.

Henrik Eskilsson

Henrik Eskilsson’s avatar

IE7 doesn’t like this JS. It adds vertical and horizontal bars instead of hiding them and showing yours. And IE7 is very confused which div to scroll with the scroll wheel, it’s perfectly random… sometime sidebar sometimes content.

Hi,

I have an issue when tabbing down a form.

When you tab through the form and the cursor gets to the bottom of the viewable scroll window and you continue to tab down the scroll bar its self starts to move up the screen and disapear so you cannot scroll back up.

Is there a fix for this?

hi………..
nice job

Is it possible, to scroll automaticaly to a specific position with javascript?
For example like Fenix said to the bottom.
I’v tried
bar.style.left = 0 + ‘px’; bar.style.top = 50 + ‘px’;bar.on_slide(0, 50);
but this only moves the trackbar.

I can move the content also with javascript, but I dont know if this leads to a consistent state, where all functions still work correctly.

This is very kewl function ….
I’m confused about how to customise look … as I can only seem to view a system scrollbar …
any tips?
Where is the look defined? javascript? css? or the xhtml calling up the scripts?
what is the z-index referring to in the css file?

sorry me bit nuB

Is there any way to get this working with text that is brought in from a xml file using ajax ? Has any one tried this yet.

Thanks.

Hey, that’s a very nice work you did, gondo.

How is the horizontal scrollbar coming along? I could use it.

Thanks

Gondo, this is simply a great script, exactly what I was looking for. Thanks!

hi, i wana thx all for yr feedback. unfortunately i dont have time these days to answer all commets. if any1 rly need help, write me an email and i would try to answer asap.
new version of js scrollbar is still underconstruction. i keep in mind all features u would like to see there.
so if u would like smthing new, write it here to comments.

Check the code in Fire Fox, or safari, when scroll, text get select

Hi!

Thank you for a simple and useful script. However my result can only be displayed through firefox. When I open the site in IE 6, I only get a conventional scrollbar.
Does anyone have an Idea why this happens?

This code could do with a major overhall. It’s really not that well writter and takes far too much advantage of the global namespace.

For a start there is no reason you should use eval() – its bad

heh well this code was done in quite a long past.
i agree its ugly written, but thats not the point.
main is, that it works.

i am coding new version, with much more better (clear) code, but its my free time project and no1 pay me for it so i do it just time to time.

why do you look at code anyway :)

How do you style the scrollbar? …Not the IE styling

Hi gondo,
Thanks for taking the time to create this script.
Before I try it I need to ask something.
Do you know whether it works within iframes?

Ahoj, diky za skvelej script, ale mam problem s kotvama v html. Kdyz je pouziju, tak to samozrejme logicky nejde, skoci v pohode, ale posuvnik se neposune. Mohl by jsi mi poradit jak to rozchodit, pokud je teda nejake reseni a podpora v kodu. Diky moc za odpoved :)

@ gondo
the script is very good…
but i dont know which kind of features are you going to add in this script that it is taking so long time… you released this version in november last year, and its been 13 months by now and no updates from your side,,, kindly let me know about the features i will add them, coz i am expert in javascript and do so many things…
do contact me back for support.
thanx!

gondo, thnx for the best
cheers frm India

-zain

Would you please tell me how can set scroll position to left of scrollholder instead of right? i mean how can use this javascript for pages with dir=”ltr” ?

RGDS

first of all : this is for me now the best and simplest scrollbar there is. I’ve tested lots of them.

Best thing of all it’s just simple Javascript WITHOUT using Mootools, jQuery or any ohter so called “modern”-time programming.

Keep up the good work!! And Keep it Simple!

I have only two remarks:
- when i scroll in FF and my mouse slides to the left it will select all content.
- can you add a top and bottom button. Just like in the regular scrollbar

Skuz : just change the colors in the classes track and drag_bar
i have added “div.drag_bar:hover { background-color:#333; }” for some more styling.

Kind regards,

Mark

Great script Gondo! :)

I was wondering… is there a way to ‘activate’ the scolling area when you click on it or when the mouse is over it? (like a regular textarea)

I am asking this because if the height of the page is bigger than the monitor resolution, when you use the mouse scoll, it scrolls the whole content of the browser’s page, not just the scrolling content.

Thanks!

Sorry, last comment has some href so i have removed in this one.

I was trying html anchors like #Professional_Sporting_Environment but when i click on the above anchor, scrollbars disaapear and after that i can not scroll. Only option is to refresh the page and then only it comes to normal stage. Can anybody help me in this as this is very urgent.

well hi folks
first of all i hate this wp and rly duno why i have to always approve all comments, all is setup write :/
nvm i ll solve it later
i am glad u like this piece of my work
in fact i have not a lot time to work on new versio but i know that onday it ll come :)
if you got some problems try to email me to
gondo at sign webdesigners dot sign sk
(if u cant read it u can find my email in about section)

i have still doubt on creating scrollbar in javascript. would you help me>

I´m using ajax in my PHP page to update the content in the scroll div. Now the scrollbar doesn´t work anymore because of the ajax scripts. Has someone experienced the same problem? …and maybe solved the problem?

Very nice and very simple to understand!
Well done m8!

One question tho,,

I want the dragbar smaller. Like a little block or so.
I tried to change some values in the css, but no Succes :(

Is there a simple solution?
Or even maybe use a .png as a dragbar?

CHeers!

great work!

i was just wondering, is there a way to alter the javascript to make it scroll faster? it behaves different form native windows scrollbars and i’d like it to behave more like the default scrollbars. please mail me!

tnx!

The scroll works great but I have a quicktime movie placed inside the div and when you scroll the movie comes outside of the div? Any help?

hi,
good script, but i’ve got problem with scroll when my div has bigger height than whole page, mouse wheel scrolls div’s content and whole page also. how to disable page scrolling when mouse pointer is over div? i really need this. thanks

Fajne ; D Przyda się na pewno ; D

hi,

Its an excellent script. Thank u…. I have got problem when using css for scrollbar. bcoz its only compatible for IE not for FF. Now its solved by ur great thinking. Once again thank u for ur nice script..

awesome piece of work. just one small problem. I’m opening a div on a button click . That div will contain this whole scrolling thing (text + scrollbars).
My problem is that in FF and Safari the contents of the divs are already shown from the beginning which should be hidden till the div is open.
I tried to hide the div explicitly and opened it while the link is clicked, but then the scrolling stylling doesn’t seems to be working in any of the browsers..

any thoughts??

THX 4 Sharing this Script ;)

Hi there.

I just found this link on Google. Your script is good but seems overly complicated for what it offers. The code ought to be simple as it’s really nothing more than drag and drop. Also, scrolling in Firefox causes all the text to be highlighted. Is that intentional or is it a bug?

Actually, I just made a scrollbar for a page on my own site: the Javascript consists of about 40 lines of code.

Please mate, add arrows to this script and it ll be perfect!

Great and simple script!

How did you create the slider inside the box. I tried using your guide and the code on the site but cant get it to work. I will give credit I just like the glowing slider. Can you post code?

http://www.landscape.sk/zahrady-prirody

Nice work but wish I were able to use it…

Hi,

Really like the script its doing a great job in firefox, safari etc however I am having a problem with it in IE7 and IE6, It is ignoring the positioning of the css… follow this link to see what I mean:

http://www.9mmpr.com/about.html

Anyone know what I can do to fix this??

Nici

Hi Gondo !

I`m also have problem with this great looking scrollbar like Drama.
Script with AJAX, jquery..simple doesen`t work.

Do you have some idea to fix this problem?

Thanks in advance,
Best regards !!!

This was exactly what I was looking for. I needed it to make very lenghty web menu appear more compact. Thanks so very much.

Thank you very much.
After 1h looking for something like this, you made the search worthy.

I can´t love you because I don´t know you, but you have saved me from hours of annoying programming…

я нашёл что искал!!!! спасибо =)

HI there

This is exactly what I am looking for BUT I need it placed horizontally at the bottom on not vertcally on the side. Please help. How do I change it?

Hey Witty,

Your codeSniplet ist exactly what i am looking for, but it dosn’t work on my Webseite. It alwasy Says: dom_remveObj ist not defined.

Did you (or anyone else) know how i can repaire this?

Thanks

Hi Gondo…

I’ve been looking for this and very happy found this page on the net.. unfortunately me,. what i need is scrolling horizontally. if you can see my site on http://www.etcshow.com/ , there will be pretty looks to add a horizontal scroller…
can you help me to make some modification to your javascript above to change scroll direction?

Thanks..

I think I found a solution for the problem with text selection while scrolling in Firefox (3.5.7):

in “scroll.js”


doDrag: function (e) {
document.body.focus(); //*enter this line
e = e? e: window.event;

if someone find solution for chrome, please let me know
thanks for the wonderful script

just ignore solution from previous post:
enter “return false;”* in “scroll.js”
.
.
.
startDrag: function (e) {
e = dw_event.DOMit(e);
if ( dw_slidebar.aniTimer ) clearInterval(dw_slidebar.aniTimer);
var bar = dw_slidebar.obj = this;
bar.downX = e.clientX; bar.downY = e.clientY;
bar.startX = parseInt(bar.style.left);
bar.startY = parseInt(bar.style.top);
bar.on_drag_start(bar.startX, bar.startY);
dw_event.add( document, “mousemove”, dw_slidebar.doDrag, true );
dw_event.add( document, “mouseup”, dw_slidebar.endDrag, true );
e.stopPropagation();
return false; / *ENTER THIS HERE*
},
.
.
.
tested in: FF, IE, Opera, Chrome, Safari. @win7×64, no problem found.
+tip: i think it would be nice to set cookie to remember scrollbar position, if i done that, i’ll let u know.
thanks again.

Great dude!
Was looking for something like this a long time ago.
I’m not an expert in javascript, so, it was killing me.

Thanks a lot!!!!

Gondo:

Thanks for making your script available to us. it’s great!

Do you know that alot of posts on the web say that custom scrollbars can only work in IE? You proved them wrong; congratulations!

When you get the chance, would you please let me klnow how I can enter the id’s for the scrollbars? The divs in my web pages already have Id and class entries.

Thanks

great script, thank you gonzo for sharing this script and thanks to bejko who provided the solution for the bug in this script

How can I find script for fix image on the right bottom corner?
Can anyone help me please?

thank you!

Thank you very much! Super script! it works perfectly!
Спасибо, Гондо! Лучший!