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.

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

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:
JQuery A Javascript Library Hard things made eas(ier) Norman White.
JQUERY/AJAX ALIREZA KHATAMIAN DELARAM YAZDANSEPAS.
The Web Warrior Guide to Web Design Technologies
JQuery Effects JQuery Animation.
Computer Information System Information System California State University Los Angeles Jongwook Woo CIS 461 Web Development I JQuery Part II Jongwook.
Philly.NET Hands-On jQuery + Plug-ins Bill Wolff, Rob Keiser.
CS 174: Web Programming April 9 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
JQuery CS 268. What is jQuery? From their web site:
CHAPTER 12 UNLEASHING JAVASCRIPT USING JQUERY. LEARNING OBJECTIVES How to download the JQuery library. How to integrate the JQuery library into an HTML.
Monday, December 1 st, 2014 Instructor: Craig Duckett Basic Animation: JavaScript and jQuery.
M. Taimoor Khan Courtesy: Norman White.
PhpXperts What is jQuery Javascript Library Fast and concise Simplifies the interaction between HTML and JavaScript.
Nguyen Ich Cuong.  Course duration: 45’  Purpose: Present Introduction to JQuery  Targeted attendees: NICorp Trainee  Tests/quiz: Yes - 10’
By Jon Marozick.  JavaScript toolkit  Aims to change the way developers think  jQuery philosophy  Find some HTML  Do something to it.
JQuery 10/21. Today jQuery Some cool tools around the web JavaScript Libraries Drawing libraries HTML Frameworks Conventions.
SERVER web page repository WEB PAGE instructions stores information and instructions BROWSER retrieves web page and follows instructions Server Web Server.
CSS/Photoshop Layouts – Quiz #7 Lecture Code:
JQuery Adding behaviour…. Lecture Plan Review of last lesson Adding behaviour –click, mouseover Animation –fade, slideDown Navigation –parent, find, next.
Bill's Amazing Content Rotator jQuery Content Rotator.
JQUERY | INTRODUCTION. jQuery  Open source JavaScript library  Simplifies the interactions between  HTML document, or the Document Object Model (DOM),
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.
Jquery Nasrullah. Jquery jQuery is a JavaScript Library. jQuery greatly simplifies JavaScript programming. jQuery is easy to learn.
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.
Animation & Effects Using JQuery. What is jQuery? jQuery is a lightweight, JavaScript library. The purpose of jQuery is to make it much easier to use.
JavaScript - A Web Script Language Fred Durao
JQuery Youn-Hee Han
CHAPTER 5 jQuery อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Introduction to jQuery. jQuery Quick facts Is a cross-compatible JavaScript library Released in 2006 by John Resig Simplifies HTML document traversing,
JQuery Introduction © Copyright 2014, Fred McClurg All Rights Reserved.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
Browser scripting jQuery Edited by: Trần Thị Mỹ Dung Ref:w3schools.com.
JavaScript Library. What is jQuery jQuery is a lightweight JavaScript library. The purpose is to make it easier to use JavaScript code on your website.
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.
Web Programming Language Week 9 Dr. Ken Cosh Introducing jQuery.
Intro to jQuery. What is jQuery? A JavaScript library Lightweight (about 31KB for the minified version) Simplifies HTML document traversing (DOM), event.
Dawn Pedersen. What is JavaScript? JavaScript is the basis for both jQuery and Spry applications JavaScript is referred to as a client-side scripting.
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.
USING JAVASCRIPT TO SHOW AN ALERT Web Design Sec 6-2 Part or all of this lesson was adapted from the University of Washington’s “Web Design & Development.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
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.
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.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Week 3: Introduction to jQuery and Adv. Javascript.
Adding Interactivity Comp 140 Fall Web 2.0 Major change in internet usage –From mostly static pages Text Graphics Simple links –To new paradigm.
JQuery Tutorial. What is jQuery jQuery is a JavaScript Library The purpose of jQuery is to make it much easier to use JavaScript on your website JavaScript.
Engr. Md. Nazim Uddin M.Sc. Eng. (CSE), B.Sc. Engg. (CSE), MIEB Cell: Website:
JQuery is a fast, small, and feature-rich javascript library. It makes things like HTML document traversal and manipulation, event handling, animation,
JQuery Element & Attribute Selectors, Events, HTML Manipulation, & CSS Manipulation.
CS7026 jQuery Effects.
Using JavaScript to Show an Alert
12/04/12 JQuery I took these slides from the site because they were pretty good looking. Instructions for editing school and department titles: Select.
jQuery A Javascript Library Hard things made eas(ier)
Tutorial 6 Topic: jQuery and jQuery Mobile Li Xu
JQUERY Online TRAINING AT GOLOGICA
JavaScript & jQuery Timers, Effects, and Animations
jQuery A Javascript Library Hard things made eas(ier)
JQuery Animation for beginners NOTES?!.
Web Programming Language
An Introduction to Animation
JavaScript & jQuery Session III
SEEM4570 Tutorial 5: jQuery + jQuery Mobile
jQuery Widgets: Tabs Requires core jQuery library + jQuery UI
Web Programming Language
Getting started with jQuery
Murach's JavaScript and jQuery (3rd Ed.)
Murach's JavaScript and jQuery (3rd Ed.)
Presentation transcript:

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  You're allowed to write on both sides 2

3 Basic Animation

4 JavaScript: Show/Hide/Toggle One of the ways that web pages often differ from applications on the desktop is how content appears. In applications, you click on something, and the application immediately makes a change to show the content or provide you with your answer. But with web pages, typically you have to reload the page or go to a completely new page. This can make the experience more disjointed—as users have to wait for the first page to load and then wait again for the second page and so on. But with HTML, CSS, and JavaScript you can create an application-style experience—and one of the easiest ways is to have HTML elements that toggle on and off when they are requested. In order to create a DIV that turns on and off, you need the following: A link or button to control the DIV (turn it on and off) The DIV to show and hide JavaScript (specifically, jQuery) to perform the action

5 jQuery: Show/Hide/Toggle Using jQuery we can accomplish the same thing using the show(), hide(), and toggle() jQuery methods. (see W3Schools jQuery Effects – Hide and Show for reference)jQuery Effects – Hide and Show $(document).ready(function() { // the 'basics' just call show/hide/toggle $('#hideLink').click(function(){ $('#someText').hide(); }); $('#showLink').click(function(){ $('#someText').show(); }); $('#toggleLink').click(function(){ $('#someText').toggle(); }); jQuery show: jQuery hide: jQuery toggle: animation_jquery_01.html animation_jquery_01.js

6 jQuery: Show/Hide/Toggle CONTINUED You can also add duration to the jQuery show(), hide(), and toggle() methods by including a speed parameter in milliseconds (see W3Schools jQuery Effects – Hide and Show for reference)jQuery Effects – Hide and Show // the 'duration' buttons all have a duration $("#showDivDur").click( function() { $("#targetDur").show(2000); // time is in milliseconds }); $("#hideDivDur").click( function() { $("#targetDur").hide(2000); }); $("#toggleDivDur").click( function() { $("#targetDur").toggle(2000); }); animation_jquery_01.html animation_jquery_01.js

7 jQuery: Show/Hide/Toggle CONTINUED You might also add an optional callback to the speed parameter which is a function to be executed after method completes (see W3Schools jQuery Effects – Hide and Show for reference)jQuery Effects – Hide and Show function callThisFunctionWhenDone() { alert("Finished the animation!"); } // 'callback' does something after the animation has finished $("#showDivCallback").click( function() { $("#targetCallback").show(1000, callThisFunctionWhenDone); // NO parentheses after function name }); $("#hideDivCallback").click( function() { $("#targetCallback").hide('slow', callThisFunctionWhenDone); }); $("#toggleDivCallback").click( function() { $("#targetCallback").toggle(2000, callThisFunctionWhenDone); }); animation_jquery_01.html animation_jquery_01.js

8 jQuery: Show/Hide/Toggle – Fade Instead of jQuery's show(), hide(), and toggle() methods you might use fadeIn(), fadeout(), and fadeToggle() instead to provide a bit more of an animation effect (see W3Schools jQuery Effects – Fading for reference)jQuery Effects – Fading $(document).ready( function() { // the 'basics' just call fadeIn/fadeOut/fadeToggle $("#fadeDivIn").click( function() { $("#target").fadeIn(); }); $("#fadeDivOut").click( function() { $("#target").fadeOut(); }); $("#fadeToggleDiv").click( function() { $("#target").fadeToggle(); }); jQuery fadeIn: jQuery fadeOut: jQuery fadeToggle: animation_jquery_02.html animation_jquery_02.js

9 jQuery: Show/Hide/Toggle – Fade CONTINUED Like the show(), hide(), and toggle() methods, the fadeIn(), fadeout(), and fadeToggle() can also include a speed parameter in milliseconds (see W3Schools jQuery Effects – Fading for reference)jQuery Effects – Fading // the 'duration' buttons all have a duration $("#fadeDivInDur").click( function() { $("#targetDur").fadeIn(2000); // time is in milliseconds }); $("#fadeDivOutDur").click( function() { $("#targetDur").fadeOut(2000); }); $("#fadeToggleDivDur").click( function() { $("#targetDur").fadeToggle(2000); }); animation_jquery_02.html animation_jquery_02.js

10 jQuery: Show/Hide/Toggle – Fade CONTINUED Also like the show(), hide(), and toggle() methods, the fadeIn(), fadeout(), and fadeToggle() can also include an optional callback along with speed parameter to call a function (see W3Schools jQuery Effects – Fading for reference)jQuery Effects – Fading function callThisFunctionWhenDone() { alert("Finished the fade animation!"); } $("#fadeDivInCallback").click( function() { $("#targetCallback").fadeIn(1500, callThisFunctionWhenDone); // Do NOT put parentheses after the function name }); $("#fadeDivOutCallback").click( function() { $("#targetCallback").fadeOut(1500, callThisFunctionWhenDone); }); $("#fadeToggleDivCallback").click( function() { $("#targetCallback").fadeToggle(1500, callThisFunctionWhenDone); }); animation_jquery_02.html animation_jquery_02.js

11 jQuery: Show/Hide/Toggle – Slide CONTINUED The slideDown(), slideUp(), and slideToggle() can also set the effect duration in the speed parameter (see W3Schools jQuery Effects – Sliding for reference)jQuery Effects – Sliding $("#slideDivDownDur").click( function() { $("#targetDur").slideDown(2000); // time is in milliseconds }); $("#slideDivUpDur").click( function() { $("#targetDur").slideUp(2000); }); $("#slideToggleDivDur").click( function() { $("#targetDur").slideToggle(2000); }); animation_jquery_03.html animation_jquery_03.js

12 jQuery: Show/Hide/Toggle – Slide CONTINUED The slideDown(), slideUp(), and slideToggle() can also include an optional callback in the speed parameter to call a function (see W3Schools jQuery Effects – Sliding for reference)jQuery Effects – Sliding function callThisFunctionWhenDone() { alert("Finished the slide animation!"); } $("#slideDivDownCallback").click( function() { $("#targetCallback").slideDown(1500, callThisFunctionWhenDone); }); // Do NOT put parentheses after the function name! $("#slideDivUpCallback").click( function() { $("#targetCallback").slideUp(1500, callThisFunctionWhenDone); }); $("#slideToggleDivCallback").click( function() { $("#targetCallback").slideToggle(1500, callThisFunctionWhenDone); }); animation_jquery_03.html animation_jquery_03.js

13 jQuery: Show/Hide/Toggle – Slide CONTINUED The slideDown(), slideUp(), and slideToggle() can also include an optional callback in the speed parameter to call a function (see W3Schools jQuery Effects – Sliding for reference)jQuery Effects – Sliding function callThisFunctionWhenDone() { alert("Finished the slide animation!"); } $("#slideDivDownCallback").click( function() { $("#targetCallback").slideDown(1500, callThisFunctionWhenDone); }); // Do NOT put parentheses after the function name! $("#slideDivUpCallback").click( function() { $("#targetCallback").slideUp(1500, callThisFunctionWhenDone); }); $("#slideToggleDivCallback").click( function() { $("#targetCallback").slideToggle(1500, callThisFunctionWhenDone); }); animation_jquery_03.html animation_jquery_03.js

14 jQuery: click and animate Methods The jQuery click(), animate(), and css() methods can be used together to create a variety of animation effects (see W3Schools jQuery click() Method, jQuery animate() Method and jQuery css() Method for reference)jQuery click() MethodjQuery animate() MethodjQuery css() Method $(document).ready(function(){ $("button").click(function(){ $("div").animate({ height:'toggle' // 'toggle' is a keyword that toggles height to 0 }); The click() method triggers the click event, or attaches a function to run when a click event occurs. The animate() method performs a custom animation of a set of CSS properties. This method changes an element from one state to another with CSS styles. The CSS property value is changed gradually, to create an animated effect. Only numeric values can be animated (like "margin:30px"). You can also use "+=" or "-=" for relative animations. NOTE: String values cannot be animated (like "background-color:red"). yh jQuery click: jQuery animate: jQuery css: animation_jquery_04.html

15 jQuery: click and animate Methods CONTINUED Below is an example of using all three of the click(), animate(), and css() methods for a unique animation effects (see W3Schools jQuery click() Method, jQuery animate() Method and jQuery css() Method for reference)jQuery click() MethodjQuery animate() MethodjQuery css() Method $(document).ready(function(){ $("button").click(function(){ startAnimation(); function startAnimation(){ $("div").animate({height:444},"slow"); $("div").animate({width:444},"slow"); $("div").css("background-color","blue"); $("div").animate({height:111},"slow"); $("div").animate({width:111},"slow",startAnimation); // calls itself } }); The strings 'fast' and 'slow' can be supplied to indicate durations of 200 and 600 milliseconds, respectively. animation_jquery_05.html

16 Basic Animation (JavaScript and jQuery): Links JavaScript Animation Tutorial JavaScript Animation Tutorial JavaScript Animation (Tutorials Point) JavaScript Animation JavaScript Image Slider (No jQuery) JavaScript Image Slider (No jQuery) JavaScript Collapsible Panels (No jQuery) JavaScript Collapsible Panels (No jQuery) JavaScript Slide Show (No jQuery) JavaScript Slide Show (No jQuery) 35 jQuery Animation Tutorials 35 jQuery Animation Tutorials script.aculo.us Animation Library script.aculo.us Animation Library Building an Image Slideshow Tutorial (JavaScript Kit) Building an Image Slideshow Tutorial