Skinned HTML Scrollbar
Well, usually I don't comment my work, but this one being a "pure technical demo", and as I had to place some content here, I will make an exception.Once upon the time I stumbled upon the great fleXcroll: Cross Browser Custom ScrollBar script by Hesido.
I was very curious to see how this was done and even possible, but looking at the JS code, I couldn't understand a bit of it. Sort of disappointed, I decided to "reinvent the [mouse] wheel" and see what I could do myself.
As always, it was just a "pushing the envelope" kind of exercice, and it might or might not work for you. Please don抰 use this in your production sites as it could divide by zero and blow up destroying the world.
My expectations:
- Minimal and plain old JS code
- No CSS hack, no "bugs compliant" features, minimum browsers work-arounds
- No JS mousewheel and keyboard event: just hook to the native OS scrolling mechanism (that's the trick, the actual scrollbars are still there, the script is just painting on top of them)
- Skinned scrollbars 100% CSS positionned, by the browser itself and not by my JS code - no lag on resize (that's the second trick)
- Zero CPU cycle used when idle - no setInterval loop
Findings :
- Avoid reading cascaded style sheet from JS (that's a mess)
- Avoid dealing with computed vs. cascaded browsers inconsistencies (that's another mess)
- Firefox is unable to know whether the left mouse button is pressed or not
- SAFARI will handle JS events outside of its window (and that's great!)
Known issues:
- Will manage vertical scrollbars only
- Won't work in Opera (onmouseup event won't fire, drawings/refresh artifacts)
- Firefox won't release the left mouse button outside of the browser windows
Developped using Firefox 2.0 + Firebug 1.0. Tests successfully passed on SAFARI win 3.0, Firefox 3 (latest alpha), IE6 and IE7.
That's all folks,
happy dhteumeuleuing :)
GF Nov 2007
查找更多代码,请访问:Zoomla!逐浪CMS