|
||
| Inside Technique : WebFX DHTML Demos : Slide Bar This script extends the generic drag-drop script to check if the the mouse is within a container boundary. Once this was finished, it became easy to build the slider. Below is a demonstration of the slide bar. Be sure not to miss the color picker demonstration for a more useful
demonstration of the slide bar. Demonstration requires Internet Explorer 4.0 or later
Catching the OnMouseDown EventThe catching of the tx = (window.event.clientX - dragobject.style.pixelLeft); This is stored in a global variable so that the positioning gets right. I also read if the onchange attribute is set and what kind of type x/y (horizontal/vertical). Show the entire code for this function! Catching the OnMouseUp EventVery simple! Just release the dragobject function moveme_onmouseup() {
if(dragobject) {
dragobject = null;
}
}
Catching the OnMouseMove EventHere the moving done. I first check if the dragobject is set, then I seperate the x and y types.
Now I check so that the mousepointer is outside of the slidebar container; if it isn't I update the
position. I also set the function moveme_onmousemove() {
if(dragobject) {
if (type=="y") {
if(event.clientY >= 0) {
if ((event.clientY - ty > 0) && (event.clientY - ty < dragobject.parentElement.style.pixelHeight - dragobject.style.pixelHeight)) {
dragobject.style.top = event.clientY - ty;
}
//Here is some extra positioning needed in case the mouse is outside the container
dragobject.value = dragobject.style.pixelTop / (dragobject.parentElement.style.pixelHeight - dragobject.style.pixelHeight);
eval(onchange.replace(/this./g, "dragobject."));
}
}
else {
...
}
window.event.returnValue = false;
window.event.cancelBubble = true;
}
}
Show the entire code for this function! setValue functionI also made a function called Percentage: 0% (Note this has been rounded to the nearest integer) Building your slidebarActually it's just a draggable element that's contained inside a container. You could have any HTML as you like.
First you create a container (SPAN or DIV) with height and width defined. Inside this you creat an element
with the You should also include the javascript file in your head like this: <script type="text/javascript" src="slidebar.js"></script> Here below is a very basic slidebar: <div style="width: 200; height: 20;"> <div class="sliderHandle" type="x" onchange="window.status = this.value)" style="width: 20; height: 100%; background: buttonface;"> </div> </div> Vertical SlidebarThis sets the type of the slider bar to "y". Demonstration requires Internet Explorer 4.0 or later Using setValueThis reads the value from the original horizontal slidebar demo and sets the vertical to the same value using: onclick="setValue(ver, hor.value)" Demonstration requires Internet Explorer 4.0 or later For a more complete and useful demonstration, see the RGB color picker. Page 1:WebFX DHTML Demos © 1997-2000 InsideDHTML.com, LLC. All rights reserved. |