开发者

why javascript onclick div slide not working?

can you tell me why this JavaScript not working .

function expand()
{
    var slidingDiv = document.getElementById("expandDiv");
    var startPosition = 350;
    var stopPosition = -150;
    if ((parseInt(slidingDiv.style.top) > stopPosition )&&(parseInt(slidingDiv.style.top) < startPosition ))
    {
        slidingDiv.style.top = parseInt(slidingDiv.style.top) + 5 + "px";
        setTimeout(expand, 5);
    }
}

.......
<a onclick="expand();">Expand</a>
<div id="expandDiv" style="width:300;height:100;background-开发者_JAVA技巧color:#fff;position:absolute;border:1px solid #ccc;">hello<br />great testing</div>


function expand()
{
    var slidingDiv = document.getElementById("expandDiv");
    var startPosition = 350;
    var stopPosition = -150;
    var value = parseInt(slidingDiv.style.top.replace("px", ""));
    if (value > stopPosition  && value  < startPosition)
    {
        slidingDiv.style.top = (value  + 5).toString() + "px";
        setTimeout(expand, 5);
    }
}

Alternatively, use jQuery to do this.

function expand()
{
    $("#expandDiv").slideDown(2000, function() {
        // Afterwards
    });
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜