Reputation: 5
i want to use the same animation for .hide()
which .fadeToggle("fast")
is using.
when you see my code you see that i use a for loop to close open divs, and if i would use there a .fadeToggle("fast")
it would open closed divs, so I am using .hide()
but i want to same animation like .fadeToggle("fast")
.
Can someone of you help me?
My Code:
$(document).ready(function () {
var anzinfos = 3;
var x = 0;
$('body').click(function (evt) {
if (evt.target.id == "info")
return;
$(".div-info-" + x).hide("fast");
});
$(".info-btn").click(function (e) {
if ($(this).attr('data') == x) {
$('.div-info-' + x).fadeToggle("fast");
} else {
for (var i = 1; i <= anzinfos; i++) {
$('.div-info-' + i).hide("fast");
}
x = $(this).attr('data');
$('.div-info-' + x).fadeToggle("fast");
}
});
})
Sorry for my bad english.
Upvotes: 0
Views: 115
Reputation: 238115
jQuery provides three methods for doing fading.
fadeToggle
"toggles" the visibility of the element, so if it is shown it will be hidden, and vice versa.
There also exist fadeIn
and fadeOut
, which do exactly the same animation as fadeToggle
, but specify which way you want to go. If the element is already visible and you do fadeIn
, nothing will happen.
You can specify the animation speed with these methods just as you can with fadeToggle
$('.div-info-' + i).fadeOut("fast");
Upvotes: 1