Simplest Rollover (nonJavaScript!)

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Chapter 08: Adding Adding Interactivity Interactivity With With Behaviors Behaviors By Bill Bennett Associate Professor MSJC CIS MVC.
Java Script Session1 INTRODUCTION.
Javascript Document Object Model. How to use JavaScript  JavaScript can be embedded into your html pages in a couple of ways  in elements in both and.
Web-based Application Development Lecture 13 February 21, 2006 Anita Raja.
Computer Science 103 Chapter 4 Advanced JavaScript.
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 and the Web Whys and Hows of Javascript.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Creating Web Documents: JavaScript, continued Tool reports Creating new windows Form input verification Homework: read about JavaScript, start planning.
JavaScript Part 1.
© 2000 – All Rights Reserved - Page 1 Introduction to JavaScript Programming Part Two.
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.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
JavaScript – Part IV Event Handlers, Images, Window object William Pegram George Mason University June 3, 2010.
Introduction to JavaScript 41 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 17.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
CSCE 102 – Chapter 9 (Functions and Parameters) CSCE General Applications Programming Benito Mendoza Benito Mendoza 1 By Benito Mendoza.
ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming images.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
Scripting and Interactivity 이병희
JavaScript – return function, time object and image rollover.
ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming control structures, events, objects.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
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.
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
Host Objects: Browsers and the DOM
Introducing DHTML. Goals Understand the concept of DHTML as a tool for creating dynamic content Understand how to use DOM properties to make changes in.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
Chapter 6 Murach's JavaScript and jQuery, C6© 2012, Mike Murach & Associates, Inc.Slide 1.
1 Lesson 6 Introducing JavaScript HTML and JavaScript BASICS, 4 th Edition.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
JAVASCRIPT A quick review. True False ■The DOM is a standardized way of referring to parts of a Web page. ■TRUE ■In the DOM, attributes have their own.
Jozef Goetz contribution, © by Pearson Education, Inc. All Rights Reserved.
The Web Wizard’s Guide To JavaScript Chapter 4 Image Swapping.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 5 Host Objects: Browsers.
COM621: Advanced Interactive Web Development Lecture 6 – JavaScript (cont.)
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.
Tarik Booker CS 120 California State University, Los Angeles.
REEM ALMOTIRI Information Technology Department Majmaah University.
Event-Driven Programming
JavaScript and HTML Simple Event Handling 11-May-18.
JavaScript is a programming language designed for Web pages.
Introduction to JavaScript Events
JavaScript: Functions
JavaScript Functions.
Programming the Web using XHTML and JavaScript
14 A Brief Look at JavaScript and jQuery.
JavaScript and HTML Simple Event Handling 19-Sep-18.
13 JavaScript: Events.
Document Object Model That’s DOM to you
Introduction to Programming the WWW I
JQuery UI Plug-ins, Object Models & the Window Object
Event Driven Programming & User Defined Functions
Events Comp 205 Fall 2017.
Working with Special Effects
JavaScript What is JavaScript? What can JavaScript do?
The Web Wizard’s Guide To JavaScript
Scripting & Interactivity
JavaScript What is JavaScript? What can JavaScript do?
Graphics Considerations
JavaScript Basics What is JavaScript?
JavaScript is a scripting language designed for Web pages by Netscape.
CNIT 133 Interactive Web Pags – JavaScript and AJAX
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

Simplest Rollover (nonJavaScript!) We’re going to change the image’s source when the event, “onmouseover” occurs: <img src = “pic.jpg” height = “250” width = “250” onmouseover = “src = ‘pic2.jpg’”> Note the quotes!! What if we want to change the image back when the mouse pointer leaves the image? <img src = “pic.jpg” height = “250” width = “250” onmouseover = “src = ‘pic2.jpg’” onmouseout = “src = ‘pic.jpg’”>

Text Rollover (nonJavaScript!) Text doesn’t have attributes (like onmouseover) So we use an anchor tag (<a>) The onmouseover attribute can change the src attribute of the <img> tag, so we need an image tag And we need to identify an image tag explicitly using the “name” attribute E.g., <img height = “100” width = “100” src = “pic3.jpg” name = “textrollover”> <a onmouseover = “document.textrollover.src = “pic4.jpg”><b>Text Rollover Example</b></a>

document.images The document.images object reflects the images on a web page. This is basically an array of all the images in a document each image is also an object of its own. you can refer to an image in one of the following ways: document.images[i] // array notation document.images.imageName // property notation

Document.images Consider the following HTML definition: <IMG SRC="anything.gif" NAME="anything" HEIGHT="100" WIDTH="100"> If this is the third image on the page, the following references reflect that image: document.images[2] // array notation document.images.anything // using the name document.anything // using the name (a shortcut) Array notation drawback: If you change the number of images on the page, the index number of your images In general, use the name.

document.images.length Returns the number of images on the page. if there are 10 images on the page, document.images.length evaluates to 10, document.images[9] reflects the last image

Browser Compatability (reminder) Not all browsers support the document.images object. only Navigator 3.0x, 4.0x, and IE 4.0x have rollovers. To make sure the browser supports the document.images object : if (document.images) { … } This statement determines whether or not the document.images object exists. If the object does not exist document.images is null, so it evaluates to false if an object is not null, it evaluates to true

Creating an Image Object var variableName = new Image(); The following statement preloads the desired image: variableName.src = "imageURL.gif"; The src property enables you to associate an actual image with an instance of the Image object.

Creating a Rollover A rollover requires at least 2 images. For example, take a look at the following images: <IMG SRC="advann.gif" HEIGHT="24" WIDTH="120" NAME="advan"> <IMG SRC="advana.gif" HEIGHT="24" WIDTH="120" NAME="advan"> Note that the active and inactive images in a rollover must both be the same size. Otherwise, the active image is automatically adjusted to the size of the inactive image.

Code for a rollover To combine these two images into a rollover: if (document.images) { var advanoff = new Image(); // for the inactive image advanoff.src = "advann.gif"; var advanon = new Image(); // for the active image advanon.src = "advana.gif"; } function act() document.images.advan.src = advanon.src; function inact() document.images.advan.src = advanoff.src; The corresponding HTML code for this rollover is: <A HREF="advantages.html" onMouseOver="act()" onMouseOut="inact()"> <IMG SRC="advann.gif" HEIGHT="24" WIDTH="120" NAME="advan" BORDER="0" ALT="Netscent Advantages"> </A>

Several Rollovers Now consider a "menu" consisting of several rollovers. Use a standard naming scheme for the variables and image names. For example: advan = the image name, advann = name of a variable Rule of thumb: use a constant suffix for inactive images, and another one for the active images. function act(imgName) { if (document.images) document.images[imgName].src = eval(imgName + "a.src"); } function inact(imgName) document.images[imgName].src = eval(imgName + "n.src"); The parameter, imgName, is used in two expressions: document.images[imgName].src // the instance imgName + "n.src" // the URL the argument is a string. By wisely choosing the variables and image names for our rollovers, we can use two general functions to activate and inactivate any image in the document.

first image is named “home” <SCRIPT LANGUAGE="JavaScript"> <!– if (document.images) { var homen = new Image(); homen.src = "homen.gif"; var homea = new Image(); homea.src = "homea.gif"; var advann = new Image(); advann.src = "advann.gif"; var advana = new Image(); advana.src = "advana.gif"; var packn = new Image(); packn.src = "packn.gif"; var packa = new Image(); packa.src = "packa.gif"; var hebrewn = new Image(); hebrewn.src = "hebrewn.gif"; var hebrewa = new Image(); hebrewa.src = "hebrewa.gif"; } function act(imgName) document.images[imgName].src = eval(imgName + "a.src"); function inact(imgName) document.images[imgName].src = eval(imgName + "n.src"); // --> </SCRIPT> In body: <A HREF="home.html" onMouseOver="act('home')" onMouseOut="inact('home')"> <IMG SRC="homen.gif" HEIGHT="24" WIDTH="120" NAME="home" BORDER="0" ALT="Home"></A><br> <A HREF="advantages.html" onMouseOver="act('advan')" onMouseOut="inact('advan')"> <IMG SRC="advann.gif" HEIGHT="24" WIDTH="120" NAME="advan" BORDER="0" ALT="Advantages"></A><br> <A HREF="pack.html" onMouseOver="act('pack')" onMouseOut="inact('pack')"> <IMG SRC="packn.gif" HEIGHT="24" WIDTH="120" NAME="pack" BORDER="0" ALT="Packages"></A><br> <A HREF="hebrew.html" onMouseOver="act('hebrew')" onMouseOut="inact('hebrew')"> <IMG SRC="hebrewn.gif" HEIGHT="24" WIDTH="120" NAME="hebrew" BORDER="0" ALT="Hebrew"></A><br> Example: first image is named “home” Its onMouseOver event invokes act() with"home". The same rule applies to the image's onMouseOut event handler. Note: the variables are named homen and homea, for the inactive and active image (respectively).

Rollover that swaps 2 images function act(imgName) { if (document.images) document.images[imgName].src = eval(imgName + "a.src"); document.images[“holder”].src = eval(imgName + “info.src”); } function inact(imgName) document.images[imgName].src = eval(imgName + "n.src"); document.images[“holder”].src = “clear.gif”; if (document.images) { var homen = new Image(); homen.src = "homen.gif"; var homea = new Image(); homea.src = "homea.gif"; var advann = new Image(); advann.src = "advann.gif"; var advana = new Image(); advana.src = "advana.gif"; var packn = new Image(); packn.src = "packn.gif"; var packa = new Image(); packa.src = "packa.gif"; var hebrewn = new Image(); hebrewn.src = "hebrewn.gif"; var hebrewa = new Image(); hebrewa.src = "hebrewa.gif"; var homeinfo = new Image(); homeinfo.src = “homeinfo.gif”; var advaninfo = new Image(); advaninfo.src = “advantagesinfo.gif”; var packinfo = new Image(); packinfo.src = “packagesinfo.gif”; var hebrewinfo = new Image(); hebrewinfo.src = “hebrewinfo.gif”; }

In Body In body: Example: first image is named “home” <A HREF="home.html" onMouseOver="act('home')" onMouseOut="inact('home')"> <IMG SRC="homen.gif" HEIGHT="24" WIDTH="120" NAME="home" BORDER="0" ALT="Home"></A><br> <A HREF="advantages.html" onMouseOver="act('advan')" onMouseOut="inact('advan')"> <IMG SRC="advann.gif" HEIGHT="24" WIDTH="120" NAME="advan" BORDER="0" ALT="Advantages"></A><br> <A HREF="pack.html" onMouseOver="act('pack')" onMouseOut="inact('pack')"> <IMG SRC="packn.gif" HEIGHT="24" WIDTH="120" NAME="pack" BORDER="0" ALT="Packages"></A><br> <A HREF="hebrew.html" onMouseOver="act('hebrew')" onMouseOut="inact('hebrew')"> <IMG SRC="hebrewn.gif" HEIGHT="24" WIDTH="120" NAME="hebrew" BORDER="0" ALT="Hebrew"></A><br> <IMG SRC = “clear.gif” Name = “holder” Height = “100” width = “100”> Example: first image is named “home” Its onMouseOver event invokes act() with"home". The same rule applies to the image's onMouseOut event handler. Note: the variables are named homen and homea, for the inactive and active image (respectively).