/    Sign up×
Community /Pin to ProfileBookmark

help me make this work in Firefox please!!

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;[/CODE]

I am calling the function with something like this:

[code]<div onmousedown=”slide(event);”></div>[/code]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @yongfook spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...