W
weston
I'm making a foray into trying to create custom vertical scrollbars and
sliders, and thought I had a basic idea how to do it, but seem to be
having some trouble with the implementation.
My thinking was:
(a) create a div for the slider / scroll nub to move within
(b) attach event handlers which, onmousedown, specify the slider/nub is
moveable, and onmouseup, specify it's not
(c) attach an event handler to the contaning div which, onmousemove,
checks to see if the slider/nub is moveable, and if it is, bring it to
the y-coordinate of the mouse within the containing div
Here's an implementation... that sortof works:
http://localhost/additional/ScrollBar/testscroll.html
You can see that if you mousedown on the nub and try to drag it, it
moves *just a little bit*... and then stops.
My code looks something like this (full listing available via view
source):
nubArea = document.getElementById('nubAreaDiv');
scrollNub = document.getElementById('scrollNubImg');
scrollNub.mobile = false;
scrollNub.onmousedown = function () { this.mobile = true; }
scrollNub.onmouseup = function () { this.mobile = false; }
scrollNub.onmouseout = function () { this.mobile = false; }
nubArea.onmousemove = function (e) {
if(scrollNub.mobile) {
coords = getMouseCoordsWithinEventTarget(e);
scrollNub.style.top = coords.y;
} }
I thought maybe having an onmouseout event on the nub which cancels its
motion might have be the problem, so I moved that event onto the
containing div by changing that line to:
nubArea.onmouseout = function () { scrollNub.mobile = false; }
That didn't seem to make any difference.
So I tried taking it out altogether:
http://weston.canncentral.org/web_lab/ScrollBar/testscroll-var2.html
That seems to change the behavior -- you do see some movement of the
scrollNub, but it's jumpy and more than a little wonky. Releaseing the
mouse click doesn't seem to stop movement. When the nub is moving, it
seems to jump back and forth between the top and the mouse position.
I'm thinking there's something I'm missing about how events are being
fired and caught, but I'm open to any feedback. Thanks!
sliders, and thought I had a basic idea how to do it, but seem to be
having some trouble with the implementation.
My thinking was:
(a) create a div for the slider / scroll nub to move within
(b) attach event handlers which, onmousedown, specify the slider/nub is
moveable, and onmouseup, specify it's not
(c) attach an event handler to the contaning div which, onmousemove,
checks to see if the slider/nub is moveable, and if it is, bring it to
the y-coordinate of the mouse within the containing div
Here's an implementation... that sortof works:
http://localhost/additional/ScrollBar/testscroll.html
You can see that if you mousedown on the nub and try to drag it, it
moves *just a little bit*... and then stops.
My code looks something like this (full listing available via view
source):
nubArea = document.getElementById('nubAreaDiv');
scrollNub = document.getElementById('scrollNubImg');
scrollNub.mobile = false;
scrollNub.onmousedown = function () { this.mobile = true; }
scrollNub.onmouseup = function () { this.mobile = false; }
scrollNub.onmouseout = function () { this.mobile = false; }
nubArea.onmousemove = function (e) {
if(scrollNub.mobile) {
coords = getMouseCoordsWithinEventTarget(e);
scrollNub.style.top = coords.y;
} }
I thought maybe having an onmouseout event on the nub which cancels its
motion might have be the problem, so I moved that event onto the
containing div by changing that line to:
nubArea.onmouseout = function () { scrollNub.mobile = false; }
That didn't seem to make any difference.
So I tried taking it out altogether:
http://weston.canncentral.org/web_lab/ScrollBar/testscroll-var2.html
That seems to change the behavior -- you do see some movement of the
scrollNub, but it's jumpy and more than a little wonky. Releaseing the
mouse click doesn't seem to stop movement. When the nub is moving, it
seems to jump back and forth between the top and the mouse position.
I'm thinking there's something I'm missing about how events are being
fired and caught, but I'm open to any feedback. Thanks!