Interview Questions

How to use Effects?

jQuery Interview Questions and Answers


(Continued from previous question...)

How to use Effects?

Simple animations with jQuery can be achieved with show() and hide().

$(document).ready(function(){
$("a").toggle(function(){
$(".stuff").hide('slow');
},function(){
$(".stuff").show('fast');
});
});

You can create any combination of animations with animate(), eg. a slide with a fade:

$(document).ready(function(){
$("a").toggle(function(){
$(".stuff").animate({ height: 'hide', opacity: 'hide' }, 'slow');
},function(){
$(".stuff").animate({ height: 'show', opacity: 'show' }, 'slow');
});
});

(Continued on next question...)

Other Interview Questions