Lecture 4 FS
Lecture 4 FS
(IT432)
Anju Mishra
Department of Information Technology
1
Module II- Introduction to jQuery
Learning Outcomes: Students will be able to recognizer various jQuery Effects, Animation
2
Outline
jQuery Effects
Hide/Show
Fade
Slide
Animate
Chaining
Q & A
3
jQuery Effects
jQuery hide(), show() and toggle() 1. $("#hide").click(function(){
• With jQuery, you can hide and show HTML elements 2. $("p").hide();
with the hide() and show() methods: 3. });
• $(selector).hide(speed,callback); 4. $("#show").click(function(){
• $(selector).show(speed,callback); 5. $("p").show();
• $(selector).toggle(speed,callback); 6. });
5
Example
$("button").click(function(){ $("button").click(function(){
$("#div1").fadeOut(); $("#div1").fadeIn();
$("#div2").fadeOut("slow"); $("#div2").fadeIn("slow");
$("#div3").fadeOut(3000); $("#div3").fadeIn(3000);
}); });
$("button").click(function(){ $("button").click(function(){
$("#div1").fadeToggle(); $("#div1").fadeTo("slow", 0.15);
$("#div2").fadeToggle("slow"); $("#div2").fadeTo("slow", 0.4);
$("#div3").fadeToggle(3000); $("#div3").fadeTo("slow", 0.7);
}); });
6
Effects - Sliding
jQuery slideDown(), slideUp(), slideToggle()
• The optional speed parameter specifies the duration of the effect. It can take the
following values: "slow", "fast", or millisecond
• The optional callback parameter is a function to be executed after the sliding completes
• jQuery has the following sliding methods:
Methosd Description Syntax
7
Example
$("#flip").click(function(){ $("#flip").click(function(){
$("#panel").slideUp(); $("#panel").slideDown();
}); });
$("#flip").click(function(){
$("#panel").slideToggle();
});
8
Effects - Animation
jQuery animate()
11
Animate – stop() method
The jQuery stop() method is used to stop an animation
or effect before it is finished. $("#stop").click(function(){
$("#panel").stop();
The stop() method works for all jQuery effect functions, });
including sliding, fading and custom animations.
Syntax: $(selector).stop(stopAll,goToEnd);
The optional stopAll parameter specifies whether also
the animation queue should be cleared or not. Default is
false, which means that only the active animation will be
stopped, allowing any queued animations to be
performed afterwards.
14
Learning Outcome
At the end of this session, you will be able to
Understand the basics of jQuery Effects Techniques
Understand the Animation methods.
Get familiar with chaining technique.
15
16
17
18
19
20