Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
65
rated 0 times [  66] [ 1]  / answers: 1 / hits: 19530  / 9 Years ago, sun, may 17, 2015, 12:00:00

I have one question about CSS hide transition using jquery hide function.



I have created this DEMO from codepen.io



In this demo you can see the show button. When you click the show button then .test and .user-image div opening with CSS transition effect .



I want to make it when clicked hide button then the .test div hide with CSS transition effect.



Anyone can tell me a little example how can i do that ?



CSS



<div class=container>
<div class=usr>Show</div>
<div class=test>
<div class=hide>Hide</div>
<div class=user-image style=background-image:url(...);></div>
</div>

</div>


JS



$(document).ready(function() {
$('.usr').click(function() {
$(.test).show();
});
$(.hide).click(function() {
$(.test).hide();
});
});

More From » jquery

 Answers
3

If you insist on using jQuery, that's very easy to achieve as well. Define the styles to transition to when showing in a separate css class .show. Add transition-duration: 0.5s; to .test.



Then



$(document).ready(function() {
$('.showHideToggle').click(function() {
var toggle= $(this);
if ($(.test).hasClass(show)) {
toggle.text(Hide);
$(.test).removeClass(show);
}
else {
toggle.text(Show);
$(.test).addClass(show);
}
});
});

[#66571] Friday, May 15, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
andrewb

Total Points: 259
Total Questions: 124
Total Answers: 90

Location: Ivory Coast
Member since Sun, Mar 7, 2021
3 Years ago
;