I have a div which should be hidden initially. Then on some event (doesn't matter) I want my div to slide up, stay for several seconds and slide down again. How could I achieve this.
Asked
Active
Viewed 54 times
2
-
Can you please provide some markup to demonstrate what you've achieved already? – Aaron Lavers Apr 19 '16 at 04:14
-
3look at css `display` property, then [slidedown](http://api.jquery.com/slidedown/) and `setTimeout()` – Arun P Johny Apr 19 '16 at 04:14
-
2http://stackoverflow.com/questions/914951/show-and-hide-divs-at-a-specific-time-interval-using-jquery – Ahsan Aziz Abbasi Apr 19 '16 at 04:18
1 Answers
4
You can use slideUp()
, slideDown()
and delay()
function anim() {
$('div')
// stop any previous animation
.stop()
// slide up the div
.slideUp()
// wait for 2 seconds
.delay(2000)
// slide down the div
.slideDown();
}
anim();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div style="height:100px;width:100px;background:black"></div>
Or using setTimeout()
instead of delay()
function anim() {
var $div = $('div')
// stop any previous animation
.stop()
// slide up the div
.slideUp();
// wait for 2 seconds
setTimeout(function() {
// slide down the div
$div.slideDown()
}, 2000);
}
anim();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div style="height:100px;width:100px;background:black"></div>

Pranav C Balan
- 113,687
- 23
- 165
- 188