PDA

View Full Version : Three times the charm and "invalid argument".



ItsMeOnly
11-08-2006, 04:28 PM
on http://www.gogolek.com I deployed nice script that "manages" sliding up/down content. Under mozilla it works flawlessly, under IE (including IE7), the slide can only be done once, sometimes twice (down->up), then IE bails out with "invalid argument".


absHeight = new Array();
tmpHeight = new Array();

tmpOpacity = new Array();

sizeInterval = new Array();
opacityInterval = new Array();

function grab() {
for (var i = 1; i <= 6; i++) {
var sectObj = document.getElementById("sect" + i);
tmpHeight[i] = 0;
absHeight[i] = sectObj.offsetHeight;

tmpOpacity[i] = "100";
}
}

function SetCookie(nr) {
var today = new Date();
var expire = new Date();
expire.setTime(today.getTime() + 3600000);
document.cookie = "section="+ nr + ";expires="+expire.toGMTString();
}

function setDimensions(nr, dim) {
var sectObj = document.getElementById("sect" + nr);

if (sectObj) {
sectObj.style.height = dim + "px";
sectObj.style.display = (tmpHeight[nr] > 0) ?
"block" : "none";
}
}

function setOpacity(nr, opacity) {
var sectObj = document.getElementById("sect" + nr);

if (sectObj) {
sectObj.style.opacity = opacity / 100;
if (nr != 1) sectObj.style.filter = "alpha(opacity:" + opacity + ")";
}
}

function hide(nr) {
if (tmpOpacity[nr] > 0) {
setOpacity(nr, tmpOpacity[nr]);
tmpOpacity[nr] -= 5;
} else {
clearInterval(opacityInterval[nr]);
setOpacity(nr, 0);
}
}

function show(nr) {
if (tmpOpacity[nr] < 100) {
setOpacity(nr, tmpOpacity[nr]);
tmpOpacity[nr] += 5;
} else {
clearInterval(opacityInterval[nr]);
setOpacity(nr, 100);
}
}

function narrow(nr) {
if (tmpHeight[nr] > 0) {
setDimensions(nr, tmpHeight[nr]);
tmpHeight[nr] -= 25;
} else {
clearInterval(sizeInterval[nr]);
setDimensions(nr, 0);
}
}

function wider(nr) {
if (tmpHeight[nr] <= absHeight[nr]) {
setDimensions(nr, tmpHeight[nr]);
tmpHeight[nr] += 35;
} else {
clearInterval(sizeInterval[nr]);
setDimensions(nr, absHeight[nr]);
}
}

function showSection(nr) {
for (var i = 1; i <= 6; i++) {
var sectObj = document.getElementById("sect" + i);
var arrowObj = document.getElementById("arrow" + i);

if (opacityInterval[i]) clearInterval(opacityInterval[i]);
if (i != nr) {
opacityInterval[i] = setInterval("hide("+i+")", 2);
} else {
opacityInterval[i] = setInterval("show("+i+")", 2);
}

if (sizeInterval[i]) clearInterval(sizeInterval[i]);
if (i != nr) {
if (arrowObj) arrowObj.src = "/img/arrow.png";
sizeInterval[i] = setInterval("narrow("+i+")", 1);
} else {
if (arrowObj) arrowObj.src = "/img/arrowdown.png";
sizeInterval[i] = setInterval("wider("+i+")", 1);
}
}

SetCookie(nr);
}

the slide is triggered by onmousedown event, with, for example
showSection(nr == 4 ? 0 : 4); nr = (nr == 4) ? 0 : 4
I'm stumbled, what is wrong with it?

EDIT: fixed: sectObj.style.height = (dim > 0 ? dim : 0) + "px";