Unit 2 — The Exciting World of JavaScript

Slides:



Advertisements
Similar presentations
Georgia Institute of Technology JavaScript part 2 Barb Ericson Georgia Institute of Technology May 2006.
Advertisements

CIS101 Introduction to Computing Week 10 Spring 2004.
CM143 - Web Week 2 Basic HTML. Links and Image Tags.
Computer Science 103 Chapter 4 Advanced JavaScript.
CIS101 Introduction to Computing Week 10. Agenda Your questions Final exam and final project CIS101 Student Survey Class presentations: Your Mad Libs.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
Unit 2 — The Exciting World of JavaScript Lesson 8 — Using JavaScript with Frames.
Lesson 2 Event Handling. Object Event Handlers Most of the objects that make up the Document Object Model respond to asynchronous, user generated events.
1 Events Lect 8. 2 Event-driven Pages one popular feature of the Web is its interactive nature e.g., you click on buttons to make windows appear e.g.,
HTML Links and Anchors.
JS: DOM Form Form Object Form Object –The Form object represents an HTML form. –For each instance of a tag in an HTML document, a Form object is created.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
Programming Games Review for midterm. Work session. Homework: Prepare for midterm.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
Adding User Interactivity – Lesson 51 Adding User Interactivity Lesson 5.
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
1 Lesson 7 Using Images with JavaScript HTML and JavaScript BASICS, 4 th Edition Barksdale / Turner.
Unit 2 — The Exciting World of JavaScript Lesson 6 — Using Images with JavaScript.
JavaScript – Part IV Event Handlers, Images, Window object William Pegram George Mason University June 3, 2010.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
44238: Dynamic Web-site Development Client Side Programming Ian Perry Room:C48 Extension:7287
Event JavaScript's interaction with HTML is handled through events that occur when the user or browser manipulates a page. When the page loads, that is.
Handling Image & Animation Using JavaScript HTML tag to display image: More options:
JavaScript – return function, time object and image rollover.
ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming control structures, events, objects.
IS2802 Introduction to Multimedia Applications for Business Lecture 3: JavaScript and Functions Rob Gleasure
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (NON-Audio version) © Dr. David C. Gibbs WDMD.
Unit 2 — The Exciting World of JavaScript Lesson 7 — Creating Forms with JavaScript.
Web Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
Understanding JavaScript and Coding Essentials Lesson 8.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
JavaScript II ECT 270 Robin Burke. Outline Functions Events and event handling Form validation.
1 Lesson 6 Introducing JavaScript HTML and JavaScript BASICS, 4 th Edition.
Adding Interactivity Comp 140 Fall Web 2.0 Major change in internet usage –From mostly static pages Text Graphics Simple links –To new paradigm.
JavaScript Wrap Up JavaScript is a versatile programming language … if you know it, you can learn others © 2004, Lawrence Snyder.
COM621: Advanced Interactive Web Development Lecture 6 – JavaScript (cont.)
Tarik Booker CS 120 California State University, Los Angeles.
REEM ALMOTIRI Information Technology Department Majmaah University.
Third lecture Event 27/2/2016 JavaScript Tutorial.
JavaScript and HTML Simple Event Handling 11-May-18.
Using DHTML to Enhance Web Pages
JavaScript is a programming language designed for Web pages.
JavaScript: Functions
JavaScript Functions.
JavaScript, continued.
Programming the Web using XHTML and JavaScript
14 A Brief Look at JavaScript and jQuery.
JavaScript and HTML Simple Event Handling 19-Sep-18.
Your 1st Programming Assignment
يمكن استدعاء الكود الوظيفي عند حدث معين أو عند استدعاء الكود الوظيفي .
Event Driven Programming & User Defined Functions
Events Comp 205 Fall 2017.
The Internet 11/29/11 Functions
Functions, Regular expressions and Events
For this assignment, copy and past the XHTML to a notepad file with the .html extension. Then add the code I ask for to complete the problems.
Recognizing JavaScript Features
JavaScript Basics What is JavaScript?
Java Script Siddharth Srivastava.
JavaScript and Ajax (JavaScript Events)
Web Programming and Design
Week 5: Recap and Portfolio Site
Barb Ericson Georgia Institute of Technology May 2006
Web Programming and Design
Web Programming and Design
Introduction to Web programming
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

Unit 2 — The Exciting World of JavaScript Lesson 6 — Using Images with JavaScript

The Exciting World of JavaScript Objectives Understand the names and usage of JavaScript events. Create an image rollover. Make a hyperlink rollover. Build a cycling banner. Display random images. Create a JavaScript slide show. The Exciting World of JavaScript

Making Graphic Images Come Alive Event: This is an operating system response to the occurrence of a specific condition. It can invoke a function. onMouseOut onMouseOver Function: This is a piece of JavaScript written by the programmer that is called upon to perform certain tasks. It can contain any number of JavaScript statements, including calls to other functions or methods. The Exciting World of JavaScript

Making Graphic Images Come Alive (cont.) To make an image rollover, you must No. 1: Define the variables. <HTML> <HEAD> <TITLE>HTML and JavaScript</TITLE> <SCRIPT> var blueArrow = new Image; var redArrow = new Image; blueArrow.src = "bluearrow.gif"; redArrow.src = "redarrow.gif"; The Exciting World of JavaScript

Making Graphic Images Come Alive (cont.) No. 2: Write the functions. function turnBlue() { document.arrow.src = blueArrow.src; return; } function turnRed() document.arrow.src = redArrow.src; The Exciting World of JavaScript

Making Graphic Images Come Alive (cont.) No. 3: Describe the events. <BODY> <CENTER> <A HREF="webpage.html" onMouseOut="turnBlue()" onMouseOver="turnRed()"> <IMG NAME="arrow" SRC="bluearrow.gif"> </A> </CENTER> </BODY> </HTML> The Exciting World of JavaScript

Making Graphic Images Come Alive (cont.) Result: the onMouseOver event turns the arrow red and onMouseOut turns the arrow blue. The Exciting World of JavaScript

The Exciting World of JavaScript Event Handling Logic Event handling: JavaScript event statements are placed within standard HTML tags. For example, the onMouseOver and onMouseOut events are located within the opening anchor (<A>) tag. These events call the functions turnBlue() and turnRed(). <A HREF= onMouseOut="turnBlue()" onMouseOver="turnRed()"> <IMG NAME="arrow" SRC="bluearrow.gif"> The Exciting World of JavaScript

Event Handling Logic (cont.) The turnBlue() and turnRed() functions call: function turnBlue() { document.arrow.src = blueArrow.src; return; } function turnRed() document.arrow.src = redArrow.src; The Exciting World of JavaScript

Event Handling Logic (cont.) The document.arrow.src = blueArrow.src; and document.arrow.src = redArrow.src; objects have already been assigned. var blueArrow = new Image; var redArrow = new Image; blueArrow.src = "bluearrow.gif"; redArrow.src = "redarrow.gif"; The Exciting World of JavaScript

Create a Cycling Banner A cycling banner is really nothing more than a sequence of graphic images that are displayed one after another with a small pause between each image change. The Exciting World of JavaScript

Creating a Cycling Banner (cont.) No. 1: Define the graphics array. <var imgArray = new Array(4); imgArray[0] = new Image; imgArray[0].src = "lions.gif"; imgArray[1] = new Image; imgArray[1].src = "tigers.gif"; imgArray[2] = new Image; imgArray[2].src = "bears.gif"; imgArray[3] = new Image; imgArray[3].src = "ohmy.gif"; var index = 0; The Exciting World of JavaScript

Creating a Cycling Banner (cont.) No. 2: Write the cycle() function. function cycle() { document.banner.src = imgArray[index].src; index++; if (index == 4) index = 0; } setTimeout("cycle()", 2000); return; The Exciting World of JavaScript

Creating a Cycling Banner (cont.) No. 3: Write the code to trigger the function. <BODY onLoad="cycle()"> <CENTER> <IMG NAME="banner" SRC="lions.gif"> </CENTER> </BODY> The Exciting World of JavaScript

Creating a Cycling Banner (cont.) Result: The graphics cycle every 2000 milliseconds. The Exciting World of JavaScript

Displaying Random Images A cycling banner can display random images one after another with a small pause between each image change. The Exciting World of JavaScript

Displaying Random Images (cont.) No. 1: Define the graphics array. <var imgArray = new Array(4); imgArray[0] = new Image; imgArray[0].src = "lions.gif"; imgArray[1] = new Image; imgArray[1].src = "tigers.gif"; imgArray[2] = new Image; imgArray[2].src = "bears.gif"; imgArray[3] = new Image; imgArray[3].src = "ohmy.gif"; var index = 0; The Exciting World of JavaScript

Displaying Random Images (cont.) Write a select() function. function select() { index = Math.floor(Math.random() * 4); document.banner.src = imgArray[index].src; setTimeout("select()", 2000); return; } The Exciting World of JavaScript

Displaying Random Images (cont.) Write the code to trigger the function. <BODY onLoad="select()"> <CENTER> <IMG NAME="banner" SRC="lions.gif"> </CENTER> </BODY> The Exciting World of JavaScript

Displaying Random Images (cont.) Result: Random graphics cycle every 2000 milliseconds. The Exciting World of JavaScript

Creating a JavaScript Slide Show When you allow the user to change the image by clicking on some object with the mouse, the end result is something akin to a slide show. The Exciting World of JavaScript

Creating a JavaScript Slide Show (cont.) No. 1: Define the array. <var imgArray = new Array(4); imgArray[0] = new Image; imgArray[0].src = "lions.gif"; imgArray[1] = new Image; imgArray[1].src = "tigers.gif"; imgArray[2] = new Image; imgArray[2].src = "bears.gif"; imgArray[3] = new Image; imgArray[3].src = "ohmy.gif"; var index = 0; The Exciting World of JavaScript

Creating a JavaScript Slide Show (cont.) No. 2: Write a doBack() function. function doBack() { if (index > 0) index--; document.slideshow.src = imgArray[index].src; } return; The Exciting World of JavaScript

Creating a JavaScript Slide Show (cont.) No. 3: Write a doNext() function. function doNext() { if (index < 3) index++; document.slideshow.src = imgArray[index].src; } return; The Exciting World of JavaScript

Creating a JavaScript Slide Show (cont.) No. 4: Write the code to trigger the functions. <BODY> <CENTER> <H2>My JavaScript Slide Show</H2> <P> <IMG NAME="slideshow" SRC="lions.gif"> <A HREF="javascript:doBack()">Back</A>     <A HREF="javascript:doNext()">Next</A> The Exciting World of JavaScript

Creating a JavaScript Slide Show (cont.) Click Next to advance and Back to return to a previous slide. The Exciting World of JavaScript

The Exciting World of JavaScript Summary You can understand the names and uses of JavaScript events. You can create an image rollover. You can make a hyperlink rollover. You can build a cycling banner. You can display random images. You can create a JavaScript slide show. The Exciting World of JavaScript