javascript - How to make two functions react on a click -
i new js.
right managed make text appear , div slide right when click on div.
the problem is: how can manage in reverse? (with same animation)
i tried if/else statement cant done. hope of can me.
here javascript code
$(document).ready(function(){ $('#profile').click(function() { $('#profile-info').fadein("").addclass('animated fadeindown'); $('#profile').animate({left:'200px'}, 800,'swing'); }); }); here html code
<section> <div id="profile"> </div> <div id="profile-photo"> </div> <div id="profile-info"> <p>hello, i'm</p> <p>rick james</p> </div> </section>
try this:
i'm using
if ( $( "#profile-info" ).is( ":hidden" ) ) { //do } else { //do } so if hidden code, if not, other desired code
$(document).ready(function(){ $('#profile').click(function() { if ( $( "#profile-info" ).is( ":hidden" ) ) { $('#profile-info').fadein("").addclass('animated fadeindown'); $('#profile').animate({left:'200px'}, 800,'swing'); } else { $('#profile-info').fadeout("").removeclass('animated fadeindown'); $('#profile').animate({left:'200px'}, 800,'swing'); } }); }); demo here: http://jsfiddle.net/yewuz/509/
updated:
jquery
$(document).ready(function(){ $('#profile').click(function() { if ( $( "#profile-info" ).is( ":hidden" ) ) { $('#profile-info').fadein("").addclass('animated fadeindown'); $('#profile-info').animate({left:'0px',opacity:1}, 800,'swing'); } else { $('#profile-info').animate({left:'200px',opacity:0}, 800,'swing'); $('#profile-info').fadeout("").removeclass('animated fadeindown'); } }); }); html
<section> <div id="profile"> test </div> <div id="profile-photo"> </div> <div id="profile-info"> <p>hello, i'm</p> <p>rick james</p> </div> </section> css
#profile-info { display: none; position:relative; left:200px; opacity:0; } demo here: http://jsfiddle.net/yewuz/512/
Comments
Post a Comment