Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using jQuery .hide() with fading

Tags:

jquery

hide

fade

I have a .hide() function that hides divs based on checkboxes.

JS Fiddle of it working here Real site example here

I'm trying to give it animation so that the .hide() will fade in/out rather than just disappear.

Tried utilising the jQuery Fade function but as a parameter for .hide() but doesn't seem to work

$("div").click(function () {       $(this).hide("fade", {}, 1000); }); 

I tried using this in my code (see JS Fiddle) as the following:

if(allSelected.length > 0){             $("div.prodGrid > div:not(" + allSelected + ")").hide("fade", {}, 1000);         } 

Where am I going wrong?

like image 516
Francesca Avatar asked Apr 23 '13 08:04

Francesca


People also ask

Which method is used to hide element with fade effect?

The jQuery fadeIn() method is used to fade in a hidden element.

How do you fadeOut in jQuery?

jQuery Effect fadeOut() MethodThe fadeOut() method gradually changes the opacity, for selected elements, from visible to hidden (fading effect). Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: This method is often used together with the fadeIn() method.

What is the difference between fadeOut and hide in jQuery?

fadeOut() the place will be removed at once. . show(duration) and . hide(duration) animate the size of element (also the opacity) to 100% and 0% and the place of elements is also animated in that duration.

Which jQuery method is used to hide?

5) Which of the following jQuery method is used to hide the selected elements? Explanation: The jQuery hide() method is used to hide the selected elements.


2 Answers

$("div").click(function () {   $(this).fadeOut(1000); }) 

There are also fadeIn and fadeToggle.

like image 185
Arnelle Balane Avatar answered Sep 19 '22 11:09

Arnelle Balane


You might use @Arnelle's solution if you want to fadeOut or

replace $(this).hide("fade", {}, 1000); with

     $(this).hide("slow");//or $(this).hide(1000); 

passing "slow" will give a nice animation before hiding your div.

Modified your fiddle with changes: http://jsfiddle.net/Z9ZVk/8/

like image 26
codefreak Avatar answered Sep 19 '22 11:09

codefreak