ok I’ve been trying to make this script work in FF for a day now and it’s really starting to frustrate me! Sorry, I’m still new at making clean cross-browser JS. This is for a dhtml “sliderbar” (like a horizontal scrollbar). Works fine in IE and Safari. I think there may be one or two properties that aren’t supported by gecko etc.
Also I think there is a problem passing the event to the next function (from slide to moveSlider). MoveSlider isn’t catching the event – I put in a little debugging and the number coordinates output for moveSlider shows up on IE and Safari but they don’t show up on FF.
Please help!
[CODE]function slide(evt) {
evt = (evt) ? evt : ((window.event) ? window.event : “”)
if (evt) {
var length = <?php echo “$length”;?>;
var from = 1;
var to = <?php echo “$number”;?>;
var count = <?php echo “$number”;?>;
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 = evt.clientX;
yCoord = evt.clientY;
document.onmousemove = moveSlider; //I don’t think the event gets passed!!
//just some debugging
document.getElementById(“debug”).innerHTML = ‘debugging: ‘ + xCoord + ‘:’ + yCoord;
}
}
function moveSlider(evt) {
evt = (evt) ? evt : ((window.event) ? window.event : “”)
if (evt) {
if (mouseover && (evt.button == 1)) {
x = pxLeft + evt.clientX – xCoord;
y = pxTop + evt.clientY – yCoord;
//more debugging
document.getElementById(“debug2”).innerHTML = ‘more debugging: ‘ + x + ‘:’ + y;
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 mouseup() {
mouseover = false;
}
document.onmouseup = mouseup;
I am calling the function with something like this:
[code]<div onmousedown=”slide(event);”></div>