Chapter 6 © 2003 by Addison-Wesley, Inc. 1 6.1 Introduction - Dynamic HTML is not a new markup language - A dynamic HTML document is one whose tag attributes,

Slides:



Advertisements
Similar presentations
© 2010 Delmar, Cengage Learning Chapter 9 Positioning Objects with AP Div Tags.
Advertisements

© Park University, 2006 Creating an Interactive Web Page with DHTML and JavaScript Park University.
Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
Chapter 6 © 2012 by Addison Wesley Longman, Inc Introduction Def: A dynamic HTML document is one whose tag attributes, tag contents, or element.
The Web Warrior Guide to Web Design Technologies
Javascript and dynamic doc presentation. Absolute positioning using CSS Absolute positioning /* A style for a paragraph of text */.regtext {font-family:
Cascading Style Sheets SP.772 May 6, CSS Useful for creating one unified look for an entire web site. Helps to seperate style from content. Can.
More javascript. Where is the cursor? (similar to my example at end of last ppt)
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Cos 381 Day 12.
20-Jun-15 JavaScript and HTML Simple Event Handling.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
Cos 381 Day 7. © 2006 Pearson Addison-Wesley. All rights reserved. 6-2 Agenda Assignment 2 Posted –Program a web-based Version of Soduku using JavaScript.
Chapter 2 Introduction to HTML5 Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
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.,
CP476 Internet Computing JavaScript and HTML1 1.JavaScript Execution Environment The JavaScript Window object represents the window in which the browser.
Tutorial 4: Using CSS for Page Layout. 2 Objectives Session 4.1 Explore CSS layout Compare types of floating layouts Examine code for CSS layouts View.
HTML DOM.  The HTML DOM defines a standard way for accessing and manipulating HTML documents.  The DOM presents an HTML document as a tree- structure.
Links in HTML. Hyperlinks or links Millions of linked web pages make up the World Wide Web Used to connect a web page to another web page on the same.
Tutorial 4 Creating Special Effects with CSS
CSS Positioning Creating Special Effects with CSS CS202 Working with Cascading Style Sheets (Chapter 4) CS202 1.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 Dynamic Documents With JavaScript.
Chapter 5 © 2003 by Addison-Wesley, Inc. 1 Chapter 5 JavaScript and HTML Documents.
Execution Environment for JavaScript " Java Script Window object represents the window in which the browser displays documents. " The Window object provides.
Chapter 5 JavaScript and HTML Documents. © 2006 Pearson Addison-Wesley. All rights reserved JavaScript Execution Environment - The JavaScript.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
JavaScript Part 1.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 JavaScript and HTML Documents.
CS346 Javascript-7A Events1 DOM Document Object Model and Events.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
DHTML - Introduction Chapter Introduction to DHTML, the DOM, JS review.
DOM Events. JS Events Outline About Events – Introduction – Registering events – Getting information from events Event order/phases – Preventing default.
JavaScript - A Web Script Language Fred Durao
Chapter 8 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 8 Sebesta: Programming the World Wide Web.
Chapter 5 © 2005 by Addison Wesley Longman, Inc JavaScript Execution Environment - The JavaScript Window object represents the window in which the.
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
Cs332a_chapt10.ppt CS332A Advanced HTML Programming DHTML Dynamic Hypertext Markup Language A term describing a series of technologies Not a stand-a-lone.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
COS 125 DAY 20. Agenda Assignment 8 not corrected yet Assignment 9 posted  Due April 16 New course time line Discussion on Scripts 
 Scripts that execute in response to some event  User clicking on something  Script does NOT execute as part of page loading  DOM facilities like.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
H.Melikyan/4910/031 Programming the World Wide Web JavaScript Dr.Hayk Melikyan Departmen of Mathematics and CS JavaScript and HTML Documents.
Host Objects: Browsers and the DOM
Chapter 6 © 2014 by Pearson Education Introduction Def: A dynamic HTML document is one whose tag attributes, tag contents, or element style properties.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
Dr. Ahmet Cengizhan Dirican BIL 374 Internet Technologies 6. Dynamic Documents With JavaScript.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
Chapter 6 Dynamic Documents with JavaScript. © 2006 Pearson Addison-Wesley. All rights reserved Introduction Def: A dynamic HTML document is.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 5 Host Objects: Browsers.
Copyright © Terry Felke-Morris Web Development & Design Foundations with HTML5 8 th Edition CHAPTER 14 KEY CONCEPTS 1 Copyright.
CIS 375—Web App Dev II DHTML. 2 Introduction to DHTML _________ HTML is “a term used by some vendors to describe the combination of HTML, style sheets.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.
6.1 Introduction 6.2 Element Positioning
THE DOM.
5.1 JavaScript Execution Environment
JavaScript and HTML Simple Event Handling 11-May-18.
Understanding Dynamic HTML Barry Sosinsky Valda Hilley
Web Development & Design Foundations with HTML5 7th Edition
JAVASCRIPTS AND HTML DOCUMENTS
JavaScript and HTML Simple Event Handling 19-Sep-18.
DHTML Javascript Internet Technology.
DHTML Javascript Internet Technology.
Tutorial 6 Creating Dynamic Pages
Web Programming and Design
6.1 Introduction 6.2 Positioning Elements
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

Chapter 6 © 2003 by Addison-Wesley, Inc Introduction - Dynamic HTML is not a new markup language - A dynamic HTML document is one whose tag attributes, tag contents, or element style properties can be changed after the document has been and is still being displayed by a browser - We will discuss only W3C standard approaches - All examples in this chapter, except the last, use the DOM 0 event model and work with both IE6 and NS6 - To make changes in a document, a script must be able to address the elements of the document using the DOM addresses of those elements 6.2 Element Positioning - HTML tables can be used for element positioning, but they lack flexibility and are slow to render - CSS-P was released by W3C in 1997

Chapter 6 © 2003 by Addison-Wesley, Inc Element Positioning (continued) - CSS-P allows us to place any element anywhere on the display, and move it later - The position of any element can be dictated by the three style properties: position, left, and top - The three possible values of position are absolute, relative, and static - Absolute Positioning <p style = "position: absolute; left: 50px; top: 100 px;">  SHOW absPos.html and Figure If an element is nested inside another element and is absolutely positioned, the top and left properties are relative to the enclosing element  SHOW absPos2.html and Figure 6.2

Chapter 6 © 2003 by Addison-Wesley, Inc Element Positioning (continued) - Relative Positioning - If no top and left properties are specified, the element is placed exactly where it would have been placed if no position property were given - But it can be moved later - If top and left properties are given, they are offsets from where it would have placed without the position property being specified - If negative values are given for top and left, the displacement is upward and to the left - Can make superscripts and subscripts --> SHOW relPos.html & Figure Static Positioning - The default value if position is not specified - Neither top nor left can be initially set, nor can they be changed later

Chapter 6 © 2003 by Addison-Wesley, Inc Moving Elements - If position is set to either absolute or relative, the element can be moved after it is displayed - Just change the top and left property values with a script --> SHOW mover.html & Figures 6.4 and Element Visibility - The visibility property of an element controls whether it is displayed - The values are visible and hidden - Suppose we want to toggle between hidden and visible, and the element’s DOM address is dom if (dom.visibility == "visible" dom.visibility = "hidden"; else dom.visibility = "visible"; --> SHOW showHide.html

Chapter 6 © 2003 by Addison-Wesley, Inc Changing Colors and Fonts - Background color is controlled by the backgroundColor property - Foreground color is controlled by the color property - Can use a function to change these two properties - Let the user input colors through text buttons - Have the text elements call the function with the element address (its name) and the new color Background color: <input type = "text" size = "10" name = "background" onchange = "setColor('background', this.value)"> - The actual parameter this.value works because at the time of the call, this is a reference to the text box (the element in which the call is made) - So, this.value is the name of the new color  SHOW dynColors.html

Chapter 6 © 2003 by Addison-Wesley, Inc Dynamic Colors and Fonts (continued) - Changing fonts - We can change the font properties of a link by using the mouseover and mouseout events to trigger a script that makes the changes - In this case, we can assign the complete script to make the changes to the element’s attribute (in the HTML) onmouseover = "this.style.color = 'blue'; this.style.font = 'italic 16pt Times';" onmouseout = "this.style.color = 'black'; this.style.font = 'normal 16pt Times';”  SHOW dynLink.html 6.6 Dynamic Content - The content of an HTML element is addressed with the value property of its associated JavaScript object  SHOW dynValue.html

Chapter 6 © 2003 by Addison-Wesley, Inc Stacking Elements - The top and left properties determine the position of an element on the display screen, which is a two-dimensional device - We can create the appearance of a third dimension by having overlapping elements, one of which covers the others (like windows) - This is done with the z-index property, which determines which element is in front and which are covered by the front element - The JavaScript variable associated with the z-index property is zIndex - The stacking order can be changed dynamically - Make the elements anchors, so they respond to mouse clicking - The href attribute can be set to call a JavaScript function by assigning it the call, with 'JAVASCRIPT' attached to the call code

Chapter 6 © 2003 by Addison-Wesley, Inc Stacking Elements (continued) - The handler function must change the zIndex value of the element - A call to the function from an element sets the zIndex value of the new top element to 10 and the zIndex value of the old top element to 0 - It also sets the current top to the new top  SHOW stacking.html 6.8 Locating the Mouse Cursor - The coordinates of the element that caused an event are available in the clientX and clientY properties of the event object - These are relative to upper left corner of the browser display window - screenX and screenY are relative to the upper left corner of the whole client screen

Chapter 6 © 2003 by Addison-Wesley, Inc Locating the Mouse Cursor (continued) - If we want to locate the mouse cursor when the mouse button is clicked, we can use the click event  SHOW where.html 6.9 Reacting to a Mouse Click - A mouse click can be used to trigger an action, no matter where the mouse cursor is in the display - Use event handlers for onmousedown and onmouseup that change the visibility attribute of the message --> SHOW anywhere.html 6.10 Slow Movement of Elements - To animate an element, it must be moved by small amounts, many times, in rapid succession - JavaScript has two ways to do this, but we cover just one: setTimeout("fun()", n)

Chapter 6 © 2003 by Addison-Wesley, Inc Slow Movement of Elements (continued) - Example: move a text element from its initial position (100, 100) to a new position (300, 300) - Use the onload attribute of the body element to initialize the position of the element (set the x and y coordinates to the top and left attributes of the element) - Use a move function to change the top and left attributes by one pixel in the direction of the destination - A problem: coordinate properties are stored as strings, which include the units ( "150px" ) - So, to do addition or subtraction with the coordinate properties, we must convert them to just numbers; the units must be replaced before the properties are used - Another problem: We need to use some HTML special characters (‘ < ‘ and ‘ -- ’) 1. XML parsers may remove all comments 2. Put the script in a CDATA section 3. Put JavaScript in separate file

Chapter 6 © 2003 by Addison-Wesley, Inc Slow Movement of Elements (continued) - These are problems of validation only - Both IE6 and NS6 deal correctly with comments  SHOW moveText.html 6.11 Dragging and Dropping an Element - We can use mouseup, mousedown, and mousemove events to grab, drag, and drop - We know how to move an element - just change its left and top properties - Example: magnetic poetry - The DOM 2 event model is required (the Event object and its property, currentTarget ) - We use both DOM 0 and DOM 2 models (DOM 0 to call the mousedown handler, grabber ) - We use three functions, grabber, mover, and dropper

Chapter 6 © 2003 by Addison-Wesley, Inc Dragging and Dropping an Element - Drag and drop requires three processes: 1. Get dom of the element to be moved when the mouse button is pressed down ( onmousedown ) while the mouse cursor is over the element to be moved - If we want to move an element in a display that has more than one element, we must first determine which element the mouse cursor is over - We can get the id of an element on which an event occurs with the srcElement property of an event object; srcElement has a property named id event.srcElement.id is the id of the element on which the event occurred

Chapter 6 © 2003 by Addison-Wesley, Inc Dragging and Dropping an Element (continued) 2. Move the element by changing its top and left properties of the element as the mouse cursor is moved ( onmousemove ) - Use event.x and event.y to track the mouse cursor 3. Dropping the element when the mouse button is released by undefining the dom used to carry out the move --> SHOW dragNDrop.html `