You can store some external variable to check at which floor ( position ) the elevator is lying. Find the below code.
<script type="text/javascript">
$(document).ready(function() {
var elevatorPosition = 0;
var elevatorMaxPosition = 3; //You can specify the maximum floors. As per your demo total 4 floor are there (0-3).
$('#up').click(function() {
if(elevatorPosition != elevatorMaxPosition)
{
elevatorPosition += 1;
$('#elevator').animate({top:'-=200px',
duration: 1000,
});
}
});
$('#down').click(function() {
if(elevatorPosition != 0)
{
elevatorPosition -= 1;
$('#elevator').animate({top:'+=200px',
duration: 1000,
});
}
});
});
</script>