Here is the code snippet:
In HTML:
<div>
<div id="div1">12345</div>
<div id="div2">67890</div>
<div id="div3"><a href="#" id="slide">abcde</a></div>
<div id="pad" style="display:none;">1234567890</div>
</div>
CSS:
#div1{width: 150px; height:50px; background-color: red;}
#div2{width: 150px; height:100px; background-color: yellow;}
#div3, #pad{width: 150px; height:20px; background-color: grey;}
#pad{height: 50px;}
JavaScript:
$("#slide").click(function(e) {
e.preventDefault();
if($("#div2").hasClass("toggled")) {
$("#div2").animate({"height": "100px"}, function() {
$("#pad").hide();}).removeClass("toggled");
}
else {
$("#div2").animate({"height": "40px"}, function() {
$("#pad").show();}).addClass("toggled");
}
});
Upon clicking the link, a grey div will slide up, resembling a keypad sliding upwards.
However, the behavior seems odd. The "pad" div only appears after the grey div has slid up and hides when it slides down. What I'm aiming for is for the "pad" to slide up and slide down smoothly, similar to opening and closing a drawer. Any suggestions?