<style>
#sq {
background-color:red;
width: 50px;
height: 50px;
}
input {
position: fixed;
left: 100px;
top: 20px;
width: 50px;
}
</style>
<div id="sq"></div>
<input type="button" value="Down" onclick="go(this)" />
<script>
var go = function (el) {
var divsq = document.getElementById("sq"),
mtop = parseInt(divsq.style.marginTop) || 0,
state = el.value == "Up",
tId = setInterval(function () {
mtop += state ? -5 : 5;
divsq.style.marginTop = mtop + "px";
if (!mtop || mtop == 80) {
el.value = state ? "Down" : "Up";
clearInterval(tId);
}
}, 30);
};
</script>