【发布时间】:2011-05-02 00:46:32
【问题描述】:
我正在尝试编写一个函数,当您单击一个元素时,它会为它绘制一个底部边框。 该函数使用元素、最小宽度和最大宽度作为参数。 当我将它与 setTimeout() 一起使用来调用自身时,它不起作用。
如果我在 setTimeout() 中使用实际数字,它可以正常工作。 我找不到问题所在...
有人可以帮忙吗?
谢谢!
function drawBorder(elem,start_wid,end_wid)
{
//Checks if the header is in starting position.
//if it is - expend the width. If not decrease the width up to the starting
//position.
if (elem.clientWidth <= start_wid)
{
increaseBorder(elem, end_wid);
}
else if (elem.clientWidth >= end_wid)
{
decreaseBorder(elem, start_wid);
}
}
function increaseBorder(elem, end_wid)
{
elem.style.width=elem.clientWidth + 3 + "px";
if (elem.clientWidth >= end_wid)
{
clearTimeout(timer2);
}
else {
var str="increaseBorder(" + elem + ", " + end_wid + ");";
timer2=setTimeout(str,3);
}
}
function decreaseBorder(elem, start_wid)
{
elem.style.width=elem.clientWidth - 3 + "px";
if (elem.clientWidth <= )
{
clearTimeout(timer2);
}
else {
var str="decreaseBorder(" + elem + ", " + start_wid + ");";
timer2=setTimeout(str,3);
}
}
【问题讨论】:
标签: javascript animation settimeout