Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 Dynamic Documents With JavaScript.

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.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Part 5 Introduction to CSS. CSS Display - Block and Inline Elements A block element is an element that takes up the full width available, and has a line.
HTML 5 and CSS 3, Illustrated Complete Unit L: Programming Web Pages with JavaScript.
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
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Cos 381 Day 12.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Cos 381 Day 9.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Computer Science 103 Chapter 4 Advanced JavaScript.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
JavaScript, Third Edition
Chapter 7: Dynamic HTML and Animation JavaScript - Introductory.
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.
Web Development & Design Foundations with XHTML Chapter 6 Key Concepts.
Copyright © Texas Education Agency, All rights reserved. 1 Web Technologies Website Development with Dreamweaver.
Web Technologies Website Development Trade & Industrial Education
Tutorial 4 Creating Special Effects with CSS
CSS Positioning Creating Special Effects with CSS CS202 Working with Cascading Style Sheets (Chapter 4) CS202 1.
Cascading Style Sheets. Defines the presentation of one or more web pages Similar to a template Can control the appearance of an entire web site giving.
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.
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.
Website Development with Dreamweaver
JavaScript, Fourth Edition
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Microsoft Visual Basic 2005 CHAPTER 7 Creating Web Applications.
COP 3813 Intro to Internet Computing Prof. Roy Levow Lecture 3.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Chapter 5 Quick Links Slide 2 Performance Objectives Understanding Framesets and Frames Creating Framesets and Frames Selecting Framesets and Frames Using.
Chapter 5: Windows and Frames
Web sites Design: Cascading Style Sheet (CSS) (Cont’d) Dimensions and Position of Elements –Width and Height Space –Table Cell Padding –Left and Top Position.
Introduction to Programming the WWW I CMSC Summer 2003 Lecture 7.
Chapter 8 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 8 Sebesta: Programming the World Wide Web.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 13 - Dynamic HTML: Object Model and Collections Outline 13.1 Introduction 13.2 Object Referencing.
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
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
JavaScript, Fourth Edition Chapter 4 Manipulating the Browser Object Model.
INTRODUCTORY Tutorial 5 Using CSS for Layout and Printing.
Know your computer Make a Folder Copy from Word to Composer Format the Font Change the Alignment Format the Background Format the Colors Insert a Picture.
Dr. Ahmet Cengizhan Dirican BIL 374 Internet Technologies 5. JavaScript and HTML Documents.
Introduction to Programming the WWW I CMSC Summer 2003 Lecture 13.
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
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.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
Dr. Ahmet Cengizhan Dirican BIL 374 Internet Technologies 6. Dynamic Documents With JavaScript.
Chapter 6 Murach's JavaScript and jQuery, C6© 2012, Mike Murach & Associates, Inc.Slide 1.
Project 7: Exploring DHTML Essentials for Design JavaScript Level Two Michael Brooks.
Chapter 10 Dynamic HTML (DHTML) JavaScript, Third Edition.
Chapter 6 Dynamic Documents with JavaScript. © 2006 Pearson Addison-Wesley. All rights reserved Introduction Def: A dynamic HTML document is.
Internet & World Wide Web How to Program, 5/e.  JavaScript events  allow scripts to respond to user interactions and modify the page accordingly  Events.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
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,
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 5 Host Objects: Browsers.
6.1 Introduction 6.2 Element Positioning
Understanding Dynamic HTML Barry Sosinsky Valda Hilley
Using DHTML to Enhance Web Pages
The Web Wizard’s Guide To DHTML and CSS
Positioning.
Tutorial 6 Creating Dynamic Pages
DREAMWEAVER MX 2004 Chapter 7 Working with Layers
Positioning.
6.1 Introduction 6.2 Positioning Elements
Presentation transcript:

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 Dynamic Documents With JavaScript

6-2 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6.1 Introduction Using DOM, JavaScript can change the document in which it is embedded Elements can be moved Style can be changed Visibility can be changed

6-3 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6.2 Element Positioning CSS provides powerful tools to position elements in a web page The position property specifies the position mode Value is absolute, relative or static The left and top properties specify element position A positive value of top pushes the element down A positive value of left pushes the element to the right A negative value of top pushes the element up A negative value of left pushes the element to the left

6-4 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6.2 Absolute Positioning Absolute position specifies where an element appears relative to the containing element Example absPos.html uses absolute positioning to overlay two pieces of text The width property is used to control the overlapping Example absPos2.html illustrates the positioning of text relative to a containing elementabsPos2.html

6-5 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6.2 Static and Relative Positioning In static position mode, the default, elements are placed left to right, top to bottom The top and left properties are ignored for static positioning Relative position mode allows changing position relative to where the element would be with static positioning This could be used to create superscripts or subscripts by moving text up or down relative to its normal position Example relPos.html illustrates positioning large text so that it looks to be centered with the remaining textrelPos.html

6-6 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6.3 Moving Elements JavaScript code can move elements by changing the top and left properties Note that the position mode has to be relative or absolute for this to work Example mover.html illustrates dynamically placing elementsmover.html Text input fields are provided to enter the x and y coordinates desired for the displayed image An image element has an id attribute and style to specify it as absolute position An event handler on a button gets values from the text fields and uses those as parameters to a JavaScript function The function gets a style node from the image element (variable dom) The top and left properties of the style element are changed (note the px appended as a unit)

6-7 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6.4 Element Visibility Example showHide.html illustrates hiding and showing an element by manipulating the visibility propertyshowHide.html The JavaScript code accesses the style node for the image element (variable dom) The visibility property of the style node is altered to change the visibility of the element

6-8 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6.5 Changing Colors and Fonts Colors and font properties can be manipulated through the style property of an element

6-9 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6.5 Changing Colors Example dynColors.html illustrates setting background and foreground colorsdynColors.html The change event is used which triggers a change depending on which text box was used Note this is used to refer to the input tag triggering the event

6-10 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6.5 Changing Fonts The dynLink example illustrates changing font properties using JavaScriptdynLink A mouseover event on a link causes the font to change A mouseout event on the same link causes the font to change back to the original

6-11 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6.6 Dynamic Content By manipulating the DOM tree representing the document, the document content can be changed The dynValue.html example illustrates dynamic content by changing the content of a text area when the mouse moves over other componentsdynValue.html The mouseover and mouseout events are used to control this The value property of the ‘help’ box is used to change the content

6-12 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6.7 Stacking Elements The z-index style property can be used to govern the layering of elements in the display If two elements both cover a part of the window, the element with the higher z-index value will cover the other one Think of a artist painting the document content on the screen. Elements with lower z-index are painted before those with higher z- index The stacking.html example illustrates manipulating the z-index property dynamicallystacking.html

6-13 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6.8 Locating the Mouse Cursor An event object created for a mouse related event has properties that give the coordinates of the mouse position at the time of the event clientX and clientY give the position in pixels relative to the upper left- hand corner of the browser window screenX and screenY give the mouse position relative to the upper left- hand corner of the screen The event object is available as an object named event In Mozilla/Firefox the object can be accessed by passing it as a parameter to the event handler In Internet Explorer, the object is a global The where.html example illustrates these pointswhere.html

6-14 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6.9 Reacting to a Mouse Click The anywhere.html example is another example using mouse location informationanywhere.html The example uses mousedown and mouseup events to drive the action The position and visibility of an element are manipulated by the event handler

6-15 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6.10 Slow Movement of Elements JavaScript provides methods to time activities setTimeout will execute some JavaScript code at one time in the future setInterval will execute a JavaScript function at evenly spaced times in the future

6-16 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6.10 Function setTimeout Takes two parameters A string containing valid JavaScript code (similar to an event attribute value) A non-negative number The call to this function immediately returns The numeric parameter specifies a number of milliseconds After that number of milliseconds, the JavaScript code is executed

6-17 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6.10 Function setInterval This function takes a variable number of parameters The first parameter is the name of a function, similar to what is used to register an event by assigning to a node property The second parameter is a number, a number of milliseconds The remaining parameters, if any, are used as parameters to the call of the function listed first This function call returns immediately Thereafter, at an interval given by the second parameter, the function is called over and over

6-18 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6.10 Example moveText.htmlmoveText.html A string of text is moved from one position to another setTimeout is used to move the text in incremental steps The function executed by setTimeout, moveText, will call setTimeout again provided the text is not in its final position The call to setTimeout includes the current text position as parameters to moveText The text position is encoded as strings with units, as required by CSS, so this text must be decoded to numerical form to perform arithmetic moveTextfuns.js moveTextfuns.js

6-19 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6.11 Dragging and Dropping Elements Example dragNDrop.html illustrates dynamically modifying event handlers in order to provide dragging and dropping functionalitydragNDrop.html The grabber method is invoked on mousedown on an element The grabber method assigns handlers for the target for the mouseup and mousemove events The grabber method also determines coordinates for the target element so that it can be properly placed when the mouse moves The mouseup event handler, dropper, undoes the event registrations The mousemove event handler moves the target element