Forum Moderators: open

Message Too Old, No Replies

help with Firefox window.event (no such thing, right?)

code works in IE, not in FF/Netscape

         

yongfook

6:13 am on Aug 10, 2005 (gmt 0)

10+ Year Member



I have some code that I need to get working in Firefox. I know the reason it doesn't work is because of the (more standard) way that FF handles events, but I'm not sure how to go about it. Do I simply change window.event to something? I read that FF needs the event manually passed to it or something? Please help!

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

yongfook

7:16 am on Aug 10, 2005 (gmt 0)

10+ Year Member



is this a step in the right direction?

*****************************

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!

yongfook

9:25 am on Aug 10, 2005 (gmt 0)

10+ Year Member



hehe can anyone help yet? I've been trying on my own...

***********************************

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]

yongfook

9:39 am on Aug 10, 2005 (gmt 0)

10+ Year Member



ps. I am calling this script with something like this:

<div onmousedown="slide(event);">blahhh</div>

is that right...?

dcrombie

4:01 pm on Aug 10, 2005 (gmt 0)



This link that might help you out:

[developer.apple.com...]

;)

yongfook

5:59 am on Aug 11, 2005 (gmt 0)

10+ Year Member



hmmm nope not really, but thanks anyway.