I'm trying to modify a javascript accordian menu to fit my boss's needs. However, now that I've made most of the adjustments, I've hit a virtual brick wall. The function expandInit() is not accepting the arguments I'm passing to it. I keep getting the "Object expected" error, but i've tested the arguments for the function using typeof() and it returns that the argument is an Object. So I'm stumped, any light that anyone could shed on this would be very helpful.
Here's the pertinent code:
function $(id){
return document.getElementById(id);
}
function expandTimer(div){
if(getHeight(div) < div.maxh){
var velocity = Math.round((div.maxh - getHeight(div)) / div.speed);
velocity = (velocity < 1) ? 1 : v;
velocity = (getHeight(div) + velocity);
setHeight(div, velocity+'px');
div.style.opacity = (velocity / div.maxh);
div.style.filter = 'alpha(opacity = '+(velocity * 100 / div.maxh)+');';
} else {
setHeight(div, div.max开发者_如何学运维h);
clearInterval(div.refRate);
}
}
//arg types are String, Int, and, String.
function accordian(mother, speed, alternate){
var motherObj = $(mother);
motherObj.activeNode='';
var allDivs = motherObj.getElementsByTagName('div');
for (var i = 0; i < allDivs.length; i++){
var divID = allDivs[i].id;
if (divID.substr(divID.indexOf('-') + 1, divID.length) == 'header'){
var contentID = divID.substr(0, divID.indexOf('-'))+'-content';
var divObj = $(divID);
divObj.contentNode = contentID;
divObj.hightlight = alternate;
var contentObj = $(contentID);
contentObj.style.display = 'none';
contentObj.style.overflow = 'hidden';
contentObj.maxh = getHeight(contentObj);
contentObj.speed = speed;
contentObj.refRate;
divObj.onmouseover = function(){
if (this.parentNode.activeNode != ''){
collapseInit($(this.parentNode.activeNode));
}
alert (typeof($(this.contentNode))); //returns 'object'
//code executes fine up until here.
expandInit($(this.contentNode));
this.parentNode.activeNode = this.contentNode;
}
}
}
}
Although I didn't include the collapseInit() code, it is having the same problem. Suffice to say that all the other functions referenced above work as intended.
EDIT: Sorry, didn't include the right function. Here's the expandInit() function:
function expandInit(div){
alert("in expandInit"); //<---does not execute.
setDisplay(div,'block');
div.style.height='0px';
clearInterval(div.refRate);
div.refRate = setInterval('expandTimer('+div+')', 10);
}
I don't see an expandInit function there, but I do see an expandTimer function...
精彩评论