Introduction to DHTML. What is DHTML? Dynamic HTML Just as Access is Dynamic Database environment Can have controls that respond to events Can have centralized.

Slides:



Advertisements
Similar presentations
1 Introduction to Web Application Implement JavaScript in HTML.
Advertisements

JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
Pemrograman Teknologi Internet W09: DOM & DHTML. 2 Objectives DOM: DOM: DOM Nodes & Trees DOM Nodes & Trees Traversing & Modifying DOM Trees Traversing.
Session 11 Dynamic HTML: Event Model and Filters Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
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.
Page 1 of 39 Javascript Chapters 13, 14 Vadim Parizher Computer Science Department California State University, Northridge Fall 2003 Slides from text Book.
Dynamic HTML (DHTML) Overview Cascading Style Sheets Document Object Model Event Model Filters and Transitions Data Binding Cross-Browser Compatibility.
Chapter 9 Introduction to the Document Object Model (DOM) JavaScript, Third Edition.
Lesson 2 Event Handling. Object Event Handlers Most of the objects that make up the Document Object Model respond to asynchronous, user generated events.
© De Montfort University, Document Object Model Howell Istance School of Computing De Montfort University.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Events.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 15 - Dynamic HTML: Filters and Transitions Outline 15.1 Introduction 15.2 Flip Filters: flipv and.
CP476 Internet Computing JavaScript and HTML1 1.JavaScript Execution Environment The JavaScript Window object represents the window in which the browser.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 13 - Dynamic HTML: Object Model and Collections Outline 13.1 Introduction 13.2 Object Referencing.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
JavaScript Part 1.
1 JavaScript: Event Model November 1, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel, and Goldberg.
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.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 13 - Dynamic HTML: Object Model and Collections Outline 13.1 Introduction 13.2 Object Referencing.
1 Dynamic HTML III: Event Model Introduction Event model –Scripts respond to user actions and change page accordingly Moving mouse Scrolling screen.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 20 – Dynamic HTML: Path, Sequencer and Sprite ActiveX Controls Outline 20.1Introduction 20.2DirectAnimation.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 16 – Dynamic HTML: Event Model Outline 16.1Introduction 16.2Event ONCLICK 16.3Event ONLOAD.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 14 - Dynamic HTML: Event Model Outline 14.1 Introduction 14.2 Event onclick 14.3 Event onload 14.4.
Pemrograman Teknologi Internet W06: Functions and Events.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 13 - Dynamic HTML: Object Model and Collections Outline 13.1 Introduction 13.2 Object Referencing.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 14 - Dynamic HTML: Event Model Outline 14.1 Introduction 14.2 Event onclick 14.3 Event onload.
 2001 Deitel & Associates, Inc. All rights reserved. 1 Chapter 20 – Dynamic HTML: Object Model and Collections Outline 20.1Introduction 20.2Object Referencing.
Chapter 15 DHTML: Filters and Transitions CIS 275—Web Application Development for Business I.
Dynamic HTML: Filters and Transitions
Dynamic HTML IV: Filters and Transitions Making Text glow glow filter –Add aura of color around text –Specify color and strength –Add padding.
JavaScript - A Web Script Language Fred Durao
Chapter 7: DHTML: Object Model and Collections CIS 275—Web Application Development for Business I.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 13 - Dynamic HTML: Object Model and Collections Outline 13.1 Introduction 13.2 Object Referencing.
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
Introduction to the Document Object Model DOM *Understand document structure manipulation *Dynamic effects in web pages *Programming, scripting, web content.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 8 Scott Marino.
Chapter 14: Dynamic HTML: Event Model Presented by: Colbie Brown CS340 Java Web Development Dr. Gloria Carter Love.
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.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
CSS1 Dynamic HTML Objects, Collections & Events. CSS2 Introduction Dynamic HTML treats HTML elements as objects. Element’s parameters can be treated as.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 16 – Dynamic HTML: Event Model Outline 16.1Introduction 16.2Event ONCLICK 16.3Event ONLOAD.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 14 - Dynamic HTML: Event Model Outline 14.1 Introduction 14.2 Event onclick 14.3 Event onload 14.4.
 2004 Prentice Hall, Inc. All rights reserved. 1 Segment – 4 Dynamic HTML & CSS.
Jaana Holvikivi 1 Introduction to Javascript Jaana Holvikivi Metropolia.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 15 - Dynamic HTML: Filters and Transitions Outline 15.1 Introduction 15.2 Flip filters: flipv.
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 17 – Dynamic HTML: Filters and Transitions Outline 17.1Introduction 17.2Flip filters: flipv.
JavaScript Event Handlers. Introduction An event handler executes a segment of a code based on certain events occurring within the application, such as.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 14 - Dynamic HTML: Event Model Outline 14.1 Introduction 14.2 Event onclick 14.3 Event onload.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 15 – Dynamic HTML: Object Model and Collections Outline 15.1Introduction 15.2Object Referencing.
Jozef Goetz contribution, © by Pearson Education, Inc. All Rights Reserved.
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
Chapter 13: DHTML: Object Model and Collections CIS 275—Web Application Development for Business I.
JavaScript and HTML Simple Event Handling 11-May-18.
Chapter 15 - Dynamic HTML: Filters and Transitions
Introduction to JavaScript Events
Chapter 14: DHTML: Event Model
Chapter 14 - Dynamic HTML: Event Model
Chapter 14 - Dynamic HTML: Event Model
13 JavaScript: Events.
Chapter 13 - Dynamic HTML: Object Model and Collections
Chapter 14 - Dynamic HTML: Event Model
Presentation transcript:

Introduction to DHTML

What is DHTML? Dynamic HTML Just as Access is Dynamic Database environment Can have controls that respond to events Can have centralized code modules Can be written in VB(script)

What is DHTML? Dynamic Hypertext Markup Language is comprised of: – CSS (cascading style sheets) – DOM (document object module) – Scripting (Javascript and VBscript) Allows for more interactivity and special effects on web pages.

Document Object Model (DOM)

DOM is an interface that permits scripts to access and update the content, structure and style of the document. Every element of the web page can be dynamically updated in response to input from the user or other programs HTML elements are treated as objects, their attributes are treated as properties of the objects The DOM has a hierarchy of elements with the window as the top level object

Dynamic HTML:Object Model and Collections The object model allows Web authors to control the presentation of their pages and gives them access to all the elements on their Web pages

Object Referencing Simplest way to reference an element is by using element’s id attributes Example: function start() { alert(pText.innerText); pText.innerText=“Thanks for coming”; } Welcome to our Web page!

Collections all and children Collections are arrays of related objects on a page. The all collection is collection (or array) of all the XHTML elements in a document, in the order in which they appear. function start() { for ( var loop = 0; loop < document.all.length; ++loop ) elements += " " + document.all[ loop ].tagName; pText.innerHTML += elements; alert( elements ); } Elements on this Web page:

Collections all and children var elements = " "; function child( object ) { var loop = 0; elements += " " + object.tagName + " "; for ( loop = 0; loop < object.children.length; loop++ ) { if ( object.children[ loo<p ].children.length ) child( object.children[ loop ] ); else elements += " " + object.children[ loop ].tagName + " "; } elements += " " + " "; } <body onload = "child( document.all[ 4 ] ); myDisplay.outerHTML += elements; myDisplay.outerHTML += ' ';"> Welcome to our Web page! Elements on this Web page:

Dynamic Styles An element’s style can be changed dynamically. Often such a change is made in response to user events. function start() { var inputColor = prompt("Enter a color name for the " + "background of this page", "" ); document.body.style.backgroundColor = inputColor; } Welcome to our Web site!

Dynamic Styles function start() { var inputClass = prompt( "Enter a className for the text “ +, "" ); pText.className = inputClass; } Welcome to our Web site!

Dynamic Positioning Dynamic Positioning enables XHTML elements to be positioned with scripting. This is done by declaring an element’s CSS position property to be either absolute or relative. Moving the element by manipulating any of the top, left, right or bottom CSS properties. We use scripting to vary the color, fontFamily or fontSize attributes.

Dynamic Positioning:Example function start() { window.setInterval( "run()", 100 ); } <p id = "pText" style = "position: absolute; left: 0; font-family: serif; color: blue"> Welcome! A similar function to setInterval is setTimeout, which takes same parameters but instead waits the specified amount of time before calling the named function only once

Dynamic Positioning:Example The clearTimeout and clearInterval functions are used to stop setTimeout and setInterval respectively For example, if you started a setTimeout timer with timer1=window.setInterval(‘run()”,200); you could then stop the timer by calling window.clearTimeout(timer1); Which would stop the timer before it fired

frames collection frames collection is useful to access those elements and objects are in different frames function start() { var text = prompt( "What is your name?", "" ); parent.frames( "lower" ).document.write( " Hello, " + text + " " ); }

navigator Object navigator object contains information about the Web browser that is viewing the page This is useful to redirecting from one browser to another browser function start() { if ( navigator.appName == "Microsoft Internet Explorer" ) { if ( navigator.appVersion.substring( 0, 1 ) >= "4" ) document.location = "newIEversion.html"; else document.location = "oldIEversion.html"; } else document.location = "NSversion.html“; }

Dynamic HTML: Event model Clicking a button, moving the mouse pointer over part of the Web page, selecting some text on the page—these actions all fire events, and a DHTML author can write code to run in response to the event.

Event onclick and onload Event onclick Click on this text! <input type = "button" value = "Click Me!" onclick = "alert( 'Hi again' )" />

Event onclick and onload Event onload function start () { alert(“Welcome to Nirma University”); }

Error Handling with onerror onerror event is used to execute specialized error-handling code window.onerror = handleError; function doThis() { alrrt( "hi" ); // alert misspelled, creates an error } function handleError( errType, errURL, errLineNum ) { window.status = "Error: " + errType + " on line " + errLineNum; return true; } <input id = "mybutton" type = "button" value = "Click Me!" onclick = "doThis()" /> This program works correctly only if “Script debugging” is disabled in IE. Tools menu->Internet Option dialog->Advanced tab->Disabled script debugging

Tracking the Mouse with Event onmousemove Event onmousemove fires repeatedly whenever the user moves the mouse over the web page. The following program uses this event to updates a coordinate display that gives the position of the mouse in the coordinate system of the object containing the mouse cursor

Tracking the Mouse with Event onmousemove function updateMouseCoordinates() { coordinates.innerText = event.srcElement.tagName + " (" + event.clientX + ", " + event.clientY + ")"; } (0, 0) <img src = "deitel.gif" style = "position: absolute; top: 100; left: 100" alt = "Deitel" />

Rollovers with onmouseover and onmouseout When the mouse cursor move over an element, an onmouseover event occurs for that element When the mouse cursor leaves the element, an onmouseout event occurs for that element <a href=" onmouseover="document.logo.src='malaram.jpg' " onmouseout ="document.logo.src='harry.gif ' " >

Form Processing with onfocus and onblur The onfocus event fires when an element gains focus. The onblur event fires when an element loses focus. var helpArray = [ "Enter your name in this input box.“, "Enter your address in this input box, “]; function helpText( messageNum ) { myForm.helpBox.value = helpArray[ messageNum ]; } Name: <input type = "text" name = "name" onfocus = "helpText(0)" onblur = "helpText(6)" /> <input type = "text" name = " " onfocus = "helpText(1)" onblur = "helpText(6)" /> </form

More Form Processing with onsubmit and onreset These two events fire when a form is submitted or reset, respectively. function formSubmit() { window.event.returnValue = false; if ( confirm ( "Are you sure you want to submit?" ) ) window.event.returnValue = true; } function formReset() { window.event.returnValue = false; if ( confirm( "Are you sure you want to reset?" ) ) window.event.returnValue = true; } <form id = "myForm" onsubmit = "formSubmit()" onreset = "formReset()" action = "">

Event Bubbling Event bubbling is the process whereby events fired in child elements “bubble” up to their parent element. function documentClick() { alert( "You clicked in the document" ); } function paragraphClick( value ) { alert( "You clicked the text" ); if ( value ) event.cancelBubble = true; } document.onclick = documentClick; Click here! Click here, too!

Dynamic HTML: Filters and Transitions Filters and transitions are specified with the CSS filter property. Applying filters to text and images causes changes that are persistent. Transitions are temporary; applying a transition allow to transfer from one page to another with pleasant visual effect, such as a random dissolve. Filters and transitions do not add content to your pages-rather, they present existing content in an engaging manner to capture the user’s attention. Filters and transitions are Microsoft technologies available only in Windows-based versions of IE6. Do not use these capabilities if you are writing other browsers

Flip Filters: flipv and fliph The flipv and fliph filters mirror text or images vertically and horizontally. Text Text

Flip Filters: flipv and fliph

Transparency with the chroma filter The chroma filter applies transparency effects dynamically, without using a graphics editor to hard-code transparency into the image. function changecolor( theColor ) { if ( theColor ) { chromaImg.filters( "chroma" ).color = theColor; chromaImg.filters( "chroma" ).enabled = true; } else chromaImg.filters( "chroma" ).enabled = false; } <img id = "chromaImg" src = "trans.gif" style ="position: absolute; filter: chroma" alt = "Transparent Image" />

Transparency with the chroma filter None Cyan Yellow Magenta Black

Transparency with the chroma filter

Creating Image masks Applying the mask filter to an image allows you to create an effect in which an element’s background is a solid color and its foreground is transparent, so the image or color behind it show through. Mask Filter AaBbCcDdEeFfGgHhIiJj KkLlMmNnOoPpQqRrSsTt <img src = "gradient.gif" width = "400" height = "200" alt = "Image with Gradient Effect" />

Creating Image masks

Image Filters: invert, gray and xray

Image Filters: invert, gray and xray

Adding shadows to Text A simple filter that adds depth to your text is the shadow filter. This filter creates a shadowing effect that gives your text a three- dimensional appearance. var shadowDirection = 0; function start() { window.setInterval( "runDemo()", 500 ); } function runDemo() { shadowText.innerText = "Shadow Direction: " + shadowDirection % 360; shadowText.filters( "shadow" ).direction = ( shadowDirection % 360 ); shadowDirection += 45; }

Adding shadows to Text <h1 id = "shadowText" style = "position: absolute; top: 25; left: 25; padding: 10; filter: shadow( direction = 0, color = red )">Shadow Direction: 0

Creating Gradient with alpha This filter is used to achieve gradient effect function run() { pic.filters( "alpha" ).opacity = opacityButton.value; pic.filters( "alpha" ).finishopacity = opacityButton2.value; pic.filters( "alpha" ).style = styleSelect.value; } <div id = "pic“ style = "position: absolute; left:0; top: 0;filter: alpha( style = 2, opacity = 100, finishopacity = 0 )"> Opacity: Color saturation of an image.

Creating Gradient with alpha

Making Text glow This filter is used to make text glow. var colorArray = [ "FF0000", "FFFF00", "00FF00“,"00FFFF", "0000FF", "FF00FF" ]; function apply() { glowSpan.filters( "glow" ).color = parseInt( glowColor.value, 16 ); glowSpan.filters( "glow" ).strength = glowStrength.value; } function startdemo() { window.setInterval( "rundemo()", 150 ); } <span id = "glowSpan" style = "position: absolute;left: 200;top: 100; padding: 5; filter: glow( color = red, strength = 5 ); font-size: 2em“>Glowing Text

Making Text glow

Creating Motion with blur The blur filter creates an illusion of motion by blurring text or image in a certain direction.