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

Slides:



Advertisements
Similar presentations
1 Lesson 9 Using JavaScript with Frames HTML and JavaScript BASICS, 4 th Edition Barksdale / Turner.
Advertisements

Introduction to TouchDevelop
Georgia Institute of Technology JavaScript part 2 Barb Ericson Georgia Institute of Technology May 2006.
Web Infrastructure Week 3 INFM 603. The Key Ideas Questions Structured Programming Modular Programming Data Structures Object-Oriented Programming.
LBSC 690 Session #10 Programming, JavaScript Jimmy Lin The iSchool University of Maryland Wednesday, November 5, 2008 This work is licensed under a Creative.
CIS101 Introduction to Computing Week 10 Spring 2004.
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.
Web Programming Material From Greenlaw/Hepp, In-line/On-line: Fundamentals of the Internet and the World Wide Web 1 Introduction The JavaScript Programming.
JavaScript Events and Event Handlers 1 An event is an action that occurs within a Web browser or Web document. An event handler is a statement that tells.
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.,
Programming Games Computer science big ideas. Computer Science jargon. Show virtual dog Homework: [Catch up: dice game, credit card or other form.] Plan.
Javascript and the Web Whys and Hows of Javascript.
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.
Creating Web Documents: JavaScript, continued Tool reports Creating new windows Form input verification Homework: read about JavaScript, start planning.
JavaScript II ECT 270 Robin Burke. Outline JavaScript review Processing Syntax Events and event handling Form validation.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
© 2000 – All Rights Reserved - Page 1 Introduction to JavaScript Programming Part Two.
JavaScript 1. What is JavaScript? JavaScript allows web authors to create dynamic pages that react to user interaction. It is an Object-based because.
Adding User Interactivity – Lesson 51 Adding User Interactivity Lesson 5.
1 Lesson 7 Using Images with JavaScript HTML and JavaScript BASICS, 4 th Edition Barksdale / Turner.
1 Introduction to Javascript Peter Atkinson. 2 Objectives To understand and use appropriately some of the basic elements of Javascript: –alert and prompt.
Announcements Assignment 9 is due Project 2 is due 7/27/04 We will be skipping chapter 22 Test 3 (chapters 18-21) will be on 7/29/04 Tip of the Day : Functions.
© 2012, Mike Murach & Associates, Inc.
CHAPTER 4 Java Script อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Functions.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
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.
Active X – Mouse Events. Structured Graphics Control  Included in Internet Explorer v5.0  Add to page with the OBJECT tag  Accessible via scripting.
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.
Lesson 16. Practical Application 1 We can take advantage of JavaScript and the DOM, to set up a form so that the first text box of a form automatically.
Project Two Adding Scrolling Messages! Page 2.4 to 2.18 Today’s Agenda Look at scrolling message coding. Create a web page with a text box. Create a web.
Event Handling (the right way). A Simple Web Page Events - Summary The web page looks like this:
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.
JavaScript II ECT 270 Robin Burke. Outline Functions Events and event handling Form validation.
Link. setTimeout() What if you want to automatically cycle through the pics? So you don’t have to keep clicking the button to see the next pic Use the.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
Introduction to TouchDevelop Lesson 3 – Comments & Lists Created by S. Johnson
1 Lesson 6 Introducing JavaScript HTML and JavaScript BASICS, 4 th Edition.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
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.)
Third lecture Event 27/2/2016 JavaScript Tutorial.
Using DHTML to Enhance Web Pages
Unit 2 — The Exciting World of JavaScript
Event Driven Programming & User Defined Functions
Events Comp 205 Fall 2017.
Functions, Regular expressions and Events
Web Design and Development
JavaScript and Ajax (JavaScript Events)
Web Programming and Design
Barb Ericson Georgia Institute of Technology May 2006
Web Programming and Design
Web Programming and Design
Presentation transcript:

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

The Exciting World of JavaScript 2 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 3 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 4 Making Graphic Images Come Alive (cont.) To make an image rollover, you must – No. 1: Define the variables. HTML and JavaScript var blueArrow = new Image; var redArrow = new Image; blueArrow.src = "bluearrow.gif"; redArrow.src = "redarrow.gif";

The Exciting World of JavaScript 5 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; return;

The Exciting World of JavaScript 6 Making Graphic Images Come Alive (cont.) No. 3: Describe the events.

The Exciting World of JavaScript 7 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 8 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 ( ) tag. These events call the functions turnBlue() and turnRed().

The Exciting World of JavaScript 9 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; return; }

The Exciting World of JavaScript 10 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 11 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 12 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 13 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 14 Creating a Cycling Banner (cont.) No. 3: Write the code to trigger the function.

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

The Exciting World of JavaScript 16 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 17 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 18 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 19 Displaying Random Images (cont.) Write the code to trigger the function.

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

The Exciting World of JavaScript 21 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 22 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 23 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 24 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 25 Creating a JavaScript Slide Show (cont.) No. 4: Write the code to trigger the functions. My JavaScript Slide Show Back Next

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

The Exciting World of JavaScript 27 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.