jQuery has a slideToggle
, and a fadeToggle
, but they don't play well together (see fiddle here):
$('div').on('click', function () {
$('span')
.slideToggle({duration: 'slow', queue: false})
.fadeToggle({duration: 'slow', queue: false});
});
How can I have slide
and fade
toggle at the same time?
The slideToggle() method toggles between slideUp() and slideDown() for the selected elements. This method checks the selected elements for visibility. slideDown() is run if an element is hidden. slideUp() is run if an element is visible - This creates a toggle effect.
jQuery fadeToggle() Method If the elements are faded out, fadeToggle() will fade them in. If the elements are faded in, fadeToggle() will fade them out. Syntax: $(selector).fadeToggle(speed,callback);
The task here is to create a slide left and right toggle effect in the JQuery, you can use the jQuery animate() method. . animate() method: It is used to change the CSS property to create the animated effect for the selected element.
The toggle() method toggles between hide() and show() for the selected elements. This method checks the selected elements for visibility. show() is run if an element is hidden. hide() is run if an element is visible - This creates a toggle effect.
Use .animate()
as follows:
$('span').animate({
height: "toggle",
opacity: "toggle"
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With