My getElementByClassName()
isn't returning any results, I had it set to getElementById()
, but I can't use the Id
since the same function will need to apply to seven links. I have filled in all the information on jsFiddle
The javascript looks like:
var myBoxWidth = 0;
var myBoxWidth2 = 0;
// show
function show() {
var myBox = document.getElementByClassName('box');
var myContent = document.getElementByClassName('content');
myContent.style.display = 'inline';
myBox.style.width = myBoxWidth + '%';
if(myBoxWidth < 80) {
myBoxWidth += 20;
setTimeout(show,55);
}
}
// hide
function hide() {
var myBox = document.getElementByClassName('box');
var myContent = document.getElementByClassName('content');
myContent.style.display = 'none';
var currentWidthVal = parseInt(myBox.style.width,10);
if(myBoxWidth2 < currentWidthVal) {
setTimeout(hide,55);
myBox.style.width = currentWidthVal = currentWidthVal - 20 + '%';
myBoxWidth = 0;
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…