jquery - Show and hide effect of div element -
i have div should hidden initially. on event (doesn't matter) want div slide up, stay several seconds , slide down again. how achieve this.
you can use slideup()
, slidedown()
, delay()
function anim() { $('div') // stop previous animation .stop() // slide div .slideup() // wait 2 seconds .delay(2000) // slide down 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 previous animation .stop() // slide div .slideup(); // wait 2 seconds settimeout(function() { // slide down 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>
Comments
Post a Comment