tags:

views:

70

answers:

1

hi,

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-color:#fff;position:absolute;border:1px solid #ccc;">hello<br />great testing</div>
+3  A: 
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
    });
}
ChaosPandion
thanks your method is working :)
Don't forget to create an account. You are more likely to get answers.
ChaosPandion
Excellent case for the usefulness of jQuery.
T Pops