Forum Moderators: open
The code is for a dhtml sliding bar.
code below
****************************************************
function moveSlider()
{
if (mouseover && (window.event.button == 1))
{
x = pxLeft + window.event.clientX - xCoord;
y = pxTop + window.event.clientY - yCoord;
if (x > xMax) x = xMax;
if (x < xMin) x = xMin;
if (y > yMax) y = yMax;
if (y < yMin) y = yMin;
sliderObject.style.pixelLeft = x;
sliderObject.style.pixelTop = y;
sliderValue = x + y;
sliderPosition = (pixelLength / valueCount) * Math.round(valueCount * sliderValue / pixelLength);
v = Math.round((sliderPosition * sliderScale + fromValue) * Math.pow(10, displayDecimals)) / Math.pow(10, displayDecimals);
displayObject.value = '.'+v+'.';
return false;
}
}
function slide(sliderID, direction, length, from, to, count, decimals, displayID)
{
pixelLength = length;
sliderScale = (to - from) / length;
if (direction == "horizontal") {
fromValue = from;
xMin = 0;
xMax = length;
yMin = 0;
yMax = 0;
}
valueCount = count - 1;
displayDecimals = decimals;
sliderObject = document.getElementById("slider");
displayObject = document.getElementById("display");
if (window.event.srcElement.id == "slider") {
mouseover = true;
pxLeft = sliderObject.style.pixelLeft;
pxTop = sliderObject.style.pixelTop;
xCoord = window.event.clientX;
yCoord = window.event.clientY;
document.onmousemove = moveSlider;
}
}
function mouseup()
{
mouseover = false;
}
document.onmouseup = mouseup;
***************************************************************
thanks in advance!
YF
*****************************
function moveSlider(e) {
if (!e) var e = window.event;
if (e)
// e gives access to the event in all browsers
if (mouseover && (e.button == 1))
{
x = pxLeft + e.clientX - xCoord;
y = pxTop + e.clientY - yCoord;
if (x > xMax) x = xMax;
if (x < xMin) x = xMin;
if (y > yMax) y = yMax;
if (y < yMin) y = yMin;
sliderObject.style.pixelLeft = x;
sliderObject.style.pixelTop = y;
sliderValue = x + y;
sliderPosition = (pixelLength / valueCount) * Math.round(valueCount * sliderValue / pixelLength);
v = Math.round((sliderPosition * sliderScale + fromValue) * Math.pow(10, displayDecimals)) / Math.pow(10, displayDecimals);
displayObject.value = '.'+v+'.';
return false;
}
}
function slide(sliderID, direction, length, from, to, count, decimals, displayID)
{
pixelLength = length;
sliderScale = (to - from) / length;
if (direction == "horizontal") {
fromValue = from;
xMin = 0;
xMax = length;
yMin = 0;
yMax = 0;
}
valueCount = count - 1;
displayDecimals = decimals;
sliderObject = document.getElementById("slider");
displayObject = document.getElementById("display");
pass();
function pass(e){
if (!e) var e = window.event;
if (e)
if (e.srcElement.id == "slider") {
mouseover = true;
pxLeft = sliderObject.style.pixelLeft;
pxTop = sliderObject.style.pixelTop;
xCoord = e.clientX;
yCoord = e.clientY;
document.onmousemove = moveSlider;
}}
}
function mouseup()
{
mouseover = false;
}
document.onmouseup = mouseup;
**********************************
This code still doesn't work in FF or Netscape though!
***********************************
function moveSlider(e) {
if (!e) e = window.event;
if (mouseover && (e.button == 1))
{
x = pxLeft + e.clientX - xCoord;
y = pxTop + e.clientY - yCoord;
if (x > xMax) x = xMax;
if (x < xMin) x = xMin;
if (y > yMax) y = yMax;
if (y < yMin) y = yMin;
sliderObject.style.pixelLeft = x;
sliderObject.style.pixelTop = y;
sliderValue = x + y;
sliderPosition = (pixelLength / valueCount) * Math.round(valueCount * sliderValue / pixelLength);
v = Math.round((sliderPosition * sliderScale + fromValue) * Math.pow(10, displayDecimals)) / Math.pow(10, displayDecimals);
displayObject.value = '.'+v+'.';
return false;
}
}
function slide(e) {
if (!e) e = window.event;
var length = 416;
var from = 1;
var to = 50;
var count = 50;
var decimals = 0;
pixelLength = length;
sliderScale = (to - from) / length;
fromValue = from;
xMin = 0;
xMax = length;
yMin = 0;
yMax = 0;
valueCount = count - 1;
displayDecimals = decimals;
sliderObject = document.getElementById("slider");
displayObject = document.getElementById("display");
mouseover = true;
pxLeft = sliderObject.style.pixelLeft;
pxTop = sliderObject.style.pixelTop;
xCoord = e.clientX;
yCoord = e.clientY;
document.onmousemove = moveSlider;
}
function mouseup()
{
mouseover = false;
}
document.onmouseup = mouseup;
********************************************************
FireFox isn't happy yet though. I have no JS errors pop up but the slidebar doesn't move.
please please please can someone help? I have a feeling the solution is really simple but this is the first time I've done something like this...
I think the problem is that it's catching the event but when it passes everything to the next function (slide() fires first, then moveSlider()) maybe the event isn't being passed? please help!1111111
1111
11
[edited by: yongfook at 9:42 am (utc) on Aug. 10, 2005]