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
});
}
精彩评论