JQuery Effects JQuery Animation.

Slides:



Advertisements
Similar presentations
The jQuery library. What is jQuery ? A javascript lightweight library Is very easy to use Is powerful Is cross-browser compatible Downloadable from jQuery.com,
Advertisements

Cascading Style Sheets
SE-2840 Dr. Mark L. Hornick1 jQuery. jQuery is a library of JavaScript functions Helps minimize the amount of JavaScript you have to write in order to:
Slide 1 CMPS 211 Internet Programming Spring 2008 Dynamic Effects with Styles Chapter 12 2/6/08.
JQuery A Javascript Library Hard things made eas(ier) Norman White.
With CSS, a color is most often specified by: a HEX value - like "#ff0000" an RGB value - like "rgb(255,0,0)" a color name - like "red“ Example h1.
Neal Stublen Transforms  Defined by the transform property Translate Rotate Scale Skew  Apply to any element without affecting.
9-May-15 More CSS. 2 A different emphasis CSS is the same for XML as it is for HTML and XHTML, but-- XML contains no display information If you want your.
Week 9 Using the Box Properties. 9-2 The CSS Visual Formatting Model Describes how the element content boxes should be displayed by the browser –Based.
Basics of Web Design Chapter 6 More CSS Basics Key Concepts 1.
Chapter 9. Links  When styling a link, you must tell CSS both what you want to style, and when you want the style to happen  Web browsers keep track.
CS320n –Visual Programming LabVIEW Foundations. Visual ProgrammingLabVIEW Foundations2 What We Will Do Today Hand back and review the midterm Look at.
MORE Cascading Style Sheets (The Positioning Model)
Basic Animation: JavaScript and jQuery.  1 week from today (next Tuesday)  You're allowed to bring a 3x5 card with anything written on it that you want.
14-Jul-15 CSS Applications to XML. 2 A different emphasis CSS is the same for XML as it is for HTML, but-- HTML already does a pretty good job of layout.
Philly.NET Hands-On jQuery + Plug-ins Bill Wolff, Rob Keiser.
Web Design Transparent Backgrounds. Why : Allow text to appear clearly above a graphic background image that still can be seen in the background. Without.
Cascading Style Sheets – Block Level. Block Level Style So far we have done text-level CSS With block level CSS, we used a generic container tag Similarly.
Slide 1 of 83 Table Borders To specify table borders in CSS, use the border property. The example below specifies a black border for table, th, and td.
CS7026 – CSS3 CSS3 – Transitions & Animations. Animating the Change with Pure CSS 2  Another nice enhancement to our heading highlight would be to either.
Getting Started.  jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions.
M. Taimoor Khan Courtesy: Norman White.
Dreamweaver -- CSS. Dreamweaver -- MX New icons are added in MX Most of the features commonly used in web design, and are same as FrontPage. New feature.
JQuery 10/21. Today jQuery Some cool tools around the web JavaScript Libraries Drawing libraries HTML Frameworks Conventions.
Basic Responsive Design Techniques. Let’s take a look at this basic layout. It has a header and two columns of text, in a box that is centered on the.
JQuery Adding behaviour…. Lecture Plan Review of last lesson Adding behaviour –click, mouseover Animation –fade, slideDown Navigation –parent, find, next.
Images in HTML Images in the foreground –src loaded separately; relative to home directory –Width & height set aside space in page; do not use this to.
Cascading Style Sheet Bayu Priyambadha, S.Kom. Definition Cascading Style Sheets (CSS) form the presentation layer of the user interface. –Structure (HTML)
INTRODUCTION TO HTML5 Using jQuery with HTML5. Introducing jQuery  Although it is not a part of any W3C or WHATWG specification, jQuery performs an important.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
COMP213 – Web Interface Design
IReport Demo Spring 2008 OEDSA Conference. Report Properties.
Introduction to jQuery. jQuery Quick facts Is a cross-compatible JavaScript library Released in 2006 by John Resig Simplifies HTML document traversing,
Web Foundations THURSDAY, OCTOBER 3, 2013 LECTURE 6: CSS CONTINUED.
Cascading Style Sheets Level 2. Course Objectives, Session 1 Level 1 Quick Review Chapter 8: Adding Graphics to Web Pages Chapter 9: Sprucing Up Your.
JQuery JavaScript is a powerful language but it is not always easy to work with. jQuery is a JavaScript library that helps with: – HTML document traversal.
THE BOX MODEL Putting layouts together with CSS. The Box Model  How would you describe a box?  Container?  Tags or elements are “containers”  puts.
Web Programming Language Week 9 Dr. Ken Cosh Introducing jQuery.
1 CS428 Web Engineering Lecture 08 Border, Margin, Padding … (CSS - III)
CSS Layout Cascading Style Sheets. Lesson Overview  In this lesson, you will learn:  CSS Box Model  CSS properties for border  CSS properties for.
CSS Layout Cascading Style Sheets. Lesson Overview  In this lesson, you will learn:  CSS properties for margin  CSS properties for dimensions (width,
IS2802 Introduction to Multimedia Applications for Business Lecture 07: Introduction to jQuery Rob Gleasure
Tutorial 7 Creating Animations. XP Objectives Learn about animation Create a timeline Add AP divs and graphics to a timeline Move and resize animation.
Introduction to JQuery COGS 187A – Fall JQuery jQuery is a JavaScript library, and allows us to manipulate HTML and CSS after the page has been.
HTML and Dreamweaver November 11th. Agenda Box Model Displaying and positioning elements – Padding – Margin – Float – Display – Position HTML Demo.
JQuery Animation. If you look at example1.html, you will see that it is a basic web page with links to the jquery library, and a script.js file and some.
Tutorial #5 Working with the Box Model. Tutorial #4 Review - CSS Create a homework page Final Project Discussion Exam on Blackboard Styling Lists (List-style-type,
Chapter 7.  Change body and link styles  Create a drop-down menu  Change color and font styles in the menu  Create a pop-up effect using CSS  Utilize.
CS 120: Introduction to Web Programming Lecture 10: Extra Features and Website Design Part 1 Tarik Booker CS 120 California State University, Los Angeles.
3.3. Managing the Graphical Interface by Using CSS. Managing the Graphical Interface by Using CSS.
CS7026 jQuery Effects.
The Box Model in CSS Web Design – Sec 4-8
Cascading Style Sheets Boxes
The Box Model in CSS Web Design – Sec 4-8
CSS Layouts: Grouping Elements
Chapter 5 Introduction to Cascading Style Sheets (CSS): Part 2
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
The Box Model in CSS Web Design – Sec 4-8
Chapter 6 More CSS Basics Key Concepts
CSS Borders and Margins.
MORE Cascading Style Sheets (The Positioning Model)
JavaScript & jQuery Timers, Effects, and Animations
DIRECTIONS: 1. Click Enable Editing in the yellow bar above.
JQuery Animation for beginners NOTES?!.
Web Programming Language
An Introduction to Animation
CSS Boxes CS 1150 Fall 2016.
Transitioning Opacity
Random Stuff Colors Sizes CSS Shortcuts.
Presentation transcript:

JQuery Effects JQuery Animation

Showing or Hiding Element // just show $(“div”).show(); // reveal slowly, slow=600ms $(“div”).show(“slow”); // hide fast, fast=200ms $(“div”).hide(“fast”); // hide or show in 100ms $(“div”).toggle(100); The “toggle” command will change whatever state the element currently has, and the parameters are both optional. The first parameter indicates the speed of the showing/hiding. If no speed is set, it will occur instantly, with no animation. A number for “speed” represents the speed in milliseconds.

Showing or Hiding Element $("#myElement").hide("slow", function() { // do something once the element is hidden } $("#myElement").show("fast", function() { // do something once the element is shown $("#myElement").toggle(1000, function() { // do something once the element is shown/hidden Remember that the “toggle” command will change whatever state the element currently has, and the parameters are both optional. The first parameter indicates the speed of the showing/hiding. If no speed is set, it will occur instantly, with no animation. A number for “speed” represents the speed in milliseconds. The second parameter is an optional function that will run when the command is finished executing.

Sliding Elements $(“div”).slideUp(); $(“div”).slideDown(“fast”); $(“div”).slideToggle(1000);

Sliding Elements $("#myElement").slideDown("fast", function() { // do something when slide down is finished } $("#myElement").slideUp("slow", function() { // do something when slide up is finished $("#myElement").slideToggle (1000, function() { // do something when slide up/down is finished

Fading === changing opacity Fading Elements $(“div”).fadeIn(“fast”); $(“div”).fadeOut(“normal”); // fade to a custom opacity $(“div”).fadeTo (“fast”, 0.5); Fading === changing opacity

Animation To animate an element, you do so by telling jQuery the CSS styles that the item should change to over time. $("#myElement").animate( { opacity: .3, width: "500px", height: "700px" }, 2000, function() { // optional callback after animation completes } );

Detecting animation completion $(“div”).hide(“slow”, function() { alert(“The DIV is hidden”); }); $(“div”).show(“fast”, function() { $(this).html(“Hello jQuery”); }); // this is a current DOM element Every effect function has a callback option

Building Custom Animations To make custom animations, you can use the animate method. $("#somelement").animate({property: value}, [speed, callback] ); You pass in each property you want animated along with the final value. The speed and callback parameters are examples of options that can be set for the method.

.animate( properties, options ) .animate( properties, [ duration ], [ easing ], [ callback ] ) properties: A map of CSS properties that the animation will move toward. options: A map of additional options to pass to the method. Supported options: duration: A string or number determining how long the animation will run. easing: A string indicating which easing function to use for the transition. callback: A function to call once the animation is complete.

.animate( properties, options ) step: A function to be called after each step of the animation. queue: A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. specialEasing: A map of one or more of the CSS properties defined by the properties argument and their corresponding easing functions (added 1.4).

jQuery - animate Not all css properties can be animated Mostly properties that take a numeric value (example: width, height, ..) Does not apply to background color, ..

.animate( properties, options ) For example, suppose you want to animate an element to 90% of its current width, you’d have to do something like: $("#somelement").animate({ width: "90%"}, 350, function(){ alert ("The animation has finished running."); }); The above snippet will animate the element to 90% of its width and then alert the user when it has finished.

.animate( properties, options ) Note that you aren’t limited to dimensions. You can animate a wide array of properties including opacity, margins, paddings, borders, font sizes. The method is also pretty flexible when it comes to units. Pixels, ems, percentages all work. So this example will work. It just won’t look cohesive. $("#somelement").animate( { width: "90%" fontSize: "14em", height: "183px", opacity: 0.8, marginTop: "2cm", marginLeft: "0.3in", borderBottom: "30mm", }, 350, function(){ alert ("The animation has finished running.");}); When defining a property which consists of more than one word, make a note to define it in camel case. It’s borderTop, not border-top.

jQuery - duration In milli-seconds Default is 400 ms Can also specify fast  200 ms slow 600 ms 1000 ms  1 second The Duration is an optional parameter, i.e. $("#cloud").animate( {"opacity": "0"}); will animate using the default duration

Custom Animation example // .animate(options, duration) $(“div”).animate({ width: “90%”, opacity: 0.5, borderWidth: “5px” }, 1000);

Chaining Animation By default animations are queued and then performed one by one ** queue is true by default Animation queuing effects are achieved in jQuery by chaining. $(“div”).animate({width: “90%”},100) .animate({opacity: 0.5},200) .animate({borderWidth: “5px”});

Controlling Animations The first animation will be performed immediately without waiting/queuing use queue parameter to disable queuing $(“div”) .animate({width: “90%”}, {queue:false, duration:1000}) .animate({opacity : 0.5});

Controlling Animations Queue only works if you’re animating the same element. To animate multiple elements sequentially, use callbacks Example: By clicking one button, several animations will happen - one after the other -

jQuery – callback function Specify a function to call after effect finishes $( “p” ).slideDown( 500, callMe ); function callMe { alert( “Do something here” ); }

Controlling Animations Set multiple callbacks. You can pass in a callback function as a parameter/option to the animate function and it will get called after the animation has completed. $(".button").click(function(){ $("#header").animate({top: "-50"}, "slow", function() { $("#something").animate({height: "hide"}, "slow", function() { $("ul#menu").animate({top: "20", left: "0"}, "slow", function() { $(".trigger").animate({height: "show", top: "110", left: "0"}, "slow"); });

A Closer Look @ some animation functions/methods

jQuery Hide and Show Element jQuery hide() Method: Example: The following jQuery code will hide the cloud element when the Hide Cloud button is clicked. $("#hideCloud").click( function(){ $("#cloud").hide(2000); });

jQuery Hide and Show Element jQuery show() Method: Example: The following jQuery code will show the cloud element when the Show Cloud button is clicked. $("#showCloud").click( function(){ $("#cloud").show(1500); });

jQuery Animate Opacity of Element

Value of Opacity Vs Transparency The degree of transparency of an element is controlled by the value of opacity: Opacity = 1 (The element is fully opaque) Opacity = 0 (The element is fully transparent or totally invisible) This can be shown in the diagram below:

Examples: Animate Element transparency The following jQuery code will animate the opacity of cloud element from 1 (i.e. fully opaque) to 0 (i.e. fully transparent or fully invisible) in 5000 milliseconds (5 seconds) when the Cloud Opacity button is clicked. $("#opacityCloudShow").click(function() { $("#cloud").animate( {"opacity": "0"}, 5000); });

jQuery Animate Element in Horizontal Direction

jQuery Animate Element in Left Direction and Right Direction By controlling the left position, the selected element can be moved to the right side or left side easily. By increasing the value to the left (+=), the element will animate to the RIGHT. By decreasing the value to the left (-=), the element will animate to the LEFT.

Examples: Animate Element right/left The following jQuery code animate the cloud element to the right side by 50 pixels when the Move Cloud to Right button is clicked. $("#moveCloudRight").click(function() { $("#cloud").animate( {"left": "+=50px"}, 4000, "linear" ); }); Example 2: The following jQuery code animate the cloud element to the left side by 50 pixels when the Move Cloud to Right button is clicked. $("#moveCloudRight").click(function() { $("#cloud").animate( {"left": "-=50px"}, 4000, "linear" ); });

jQuery Animate Element in Vertical Direction

jQuery Animate Element up/down By controlling the top position, the selected element can be moved up and down easily. By increasing the value to the top (+=), the element will animate DOWN. By decreasing the value to the top (-=), the element will animate UP.

Examples: Animate Element up/down The following jQuery code animate the sun element UP by 30 pixels when the Move Sun Up button is clicked. $("#moveSunUp").click(function() { $("#sun").animate( {"top": "-=30px"}, 4000, "linear" ); }); Example 2: The following jQuery code animate the sun element DOWN by 30 pixels when the Move Sun Down button is clicked. $("#moveSunDown").click(function() { $("#sun").animate( {"top": "+=30px"}, 4000, "linear" ); });

jQuery Resize Width and Height of Element The above jQuery example resize the selected element by increasing the width and height.

jQuery Resize Element The selected element can be resized bigger or smaller By increasing the value of height (+=), the height will animate taller. By decreasing the value of height (-=), the height will animate shorter. By increasing the value of width (+=), the width will animate wider. By decreasing the value of width (-=), the width will animate shorter.

jQuery Resize Width and Height of Element Another way to resize selected element is to animate the selected element to a specified height and width.

Examples: Resize Width and Height The following jQuery code resizes or animates the frame element by increasing the height by 30 pixels and increasing the width by 40 pixels when the Frame Resize button is clicked. $("#frameSizeChange").click(function() { $("#frame").animate( {"height": "+=30px", "width": "+=40px"}, 1000 ); }); Example 2: The following jQuery code animates the frame element by setting the height to 270 pixels and the width to 650 pixels when the Frame Resume button is clicked. $("#frameSizeResume").click(function() { $("#frame").animate( {"height": "270px", "width": "650px"}, 1000 ); });

Examples: Callback jQuery Callback example: An alert box with the message "Animation completed!" will pop up after the animation is completed. $("#moveSunDown").click(function() { $("#sun").animate( {"top": "+=50px"}, 5000, function() { showComplete() } ); }); function showComplete(){ alert("Animation completed!"); } The callback parameter can also be written as below: $("#moveSunDown").click(function() { $("#sun").animate( {"top": "+=50px"}, 5000, function() { alert("Animation Completed"); } ); }); An alert box with the message "Animation completed! The cloud is fully transparent now!" will pop up after the animation is completed. $("#opacityCloudShow").click(function() { $("#cloud").animate( {"opacity": "0"}, 5000, function() { showComplete() } ); }); function showComplete(){ alert("Animation completed! The cloud is fully transparent now!"); } The callback parameter can also be written as below: $("#opacityCloudShow").click(function() { $("#cloud").animate( {"opacity": "0"}, 5000, function() { alert("Animation Completed"); } ); });