Add and remove a class with animation

I wrote a script that changes the color of a box in another field: http://jsfiddle.net/w5b9v/2/

How to add animation to this transition? thanks in advance

-one
jquery
Feb 22 2018-11-28T00:
source share
2 answers

You could do something this way http://jsfiddle.net/steweb/fn68L/

JS:

$(document).ready(function(){ $(".wrapper div.me:last").addClass("reduce"); $(".wrapper div.me").hover( function(){ $(this).fadeTo('fast',1); //or $(this).animate({opacity:1},300/*ms*/) $(".wrapper div").not(this).fadeTo('fast',0.8); }); }); 

Or you can check animate in a jquery plugin class ;)

+1
Feb 22 2018-11-22T00:
source share

The jQuery.animate method animates mostly numeric properties and does not cover the addition of a class subtraction.

If you just want to change the opacity, you can use . fadeTo .

 $(".wrapper div").not(this).fadeTo('slow', 0.5); 

The above will reduce the opacity by half.

This question contains additional information, including the jQueryUI switchClass method. This question also offers a plugin . AnimateToSelector .

Finally, there is animateToClass , but this apparently just transfers the .animate functions to the class, which means numerical values โ€‹โ€‹will not work.

+1
Feb 22 2018-11-21T00:
source share



All Articles