ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming DHTML Example.

Slides:



Advertisements
Similar presentations
© Park University, 2006 Creating an Interactive Web Page with DHTML and JavaScript Park University.
Advertisements

JQuery CS 380: Web Programming. What is jQuery? jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling,
DHTML 1 (cont.) Positioning, Layout, and Movement.
The Web Warrior Guide to Web Design Technologies
Dynamic HTML Netscape Navigator (NN) 6.0 & Internet Explorer (IE) 5.0.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
Tutorial 10 Programming with JavaScript
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
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.
DHTML - Introduction Introduction to DHTML, the DOM, JS review.
4.1 JavaScript Introduction
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Tutorial 4 Creating Special Effects with CSS
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.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 Dynamic Documents With JavaScript.
Execution Environment for JavaScript " Java Script Window object represents the window in which the browser displays documents. " The Window object provides.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming DOM.
DHTML Positioning and Layout. What is DHTML? HTML and xHTML CSS JavaScript or VBScript.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Creating an Animated Web Page
Working with Objects Creating a Dynamic Web Page.
CITS1231 Web Technologies JavaScript and Document Object Model.
XP Tutorial 4 New Perspectives on JavaScript, Comprehensive1 Working with Objects Creating an Animated Web Page.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
Advanced DHTML.
ASP.NET.. ASP.NET Environment ASP.NET is Microsoft's programming framework that enables the development of Web applications and services. It is an easy.
JavaScript, Fourth Edition
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Introduction to JavaScript 41 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 17.
DHTML - Introduction Chapter Introduction to DHTML, the DOM, JS review.
 2001 Deitel & Associates, Inc. All rights reserved. 1 Chapter 20 – Dynamic HTML: Object Model and Collections Outline 20.1Introduction 20.2Object Referencing.
DHTML: Working with Objects Creating a Dynamic Web Page.
Tutorial 5 Windows and Frames Section B - Working with Frames and Other Objects Go to Other Objects.
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.
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.2 Revised by Dr. T. Tran for CSI3140.
Cascading Style Sheets Positioning Controls Visibility.
INTRODUCTORY Tutorial 5 Using CSS for Layout and Printing.
Chapter 6 © 2014 by Pearson Education Introduction Def: A dynamic HTML document is one whose tag attributes, tag contents, or element style properties.
Understanding JavaScript and Coding Essentials Lesson 8.
Dr. Ahmet Cengizhan Dirican BIL 374 Internet Technologies 6. Dynamic Documents With JavaScript.
The Web Wizard’s Guide To DHTML and CSS Chapter 2 A Review of CSS2 and JavaScript.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 15 – Dynamic HTML: Object Model and Collections Outline 15.1Introduction 15.2Object Referencing.
Project 7: Exploring DHTML Essentials for Design JavaScript Level Two Michael Brooks.
Chapter 10 Dynamic HTML (DHTML) JavaScript, Third Edition.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript IV Robin Burke ECT 270. Outline Final project reminder Style review Manipulating style Special effect examples.
Chapter 6 Dynamic Documents with JavaScript. © 2006 Pearson Addison-Wesley. All rights reserved Introduction Def: A dynamic HTML document is.
Working with Dynamic Page Layout Maureen Smith Professor, Saddleback College CIM 271B - Tutorial 1.
The Web Wizard’s Guide To DHTML and CSS Chapter 2 A Review of CSS2 and JavaScript.
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,
REEM ALMOTIRI Information Technology Department Majmaah University.
1 The Document Object Model. 2 Objectives You will be able to: Describe the structure of the W3C Document Object Model, or DOM. Use JavaScript to access.
6.1 Introduction 6.2 Element Positioning
Programming Web Pages with JavaScript
Using DHTML to Enhance Web Pages
Unit M Programming Web Pages with
Applied Online Programming
Unit M Programming Web Pages with
JAVASCRIPTS AND HTML DOCUMENTS
14 A Brief Look at JavaScript and jQuery.
DHTML Javascript Internet Technology.
DHTML Javascript Internet Technology.
Working with Dynamic Content and Styles
Introduction to DHTML, the DOM, JS review
6.1 Introduction 6.2 Positioning Elements
Presentation transcript:

ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming DHTML Example

ECA 225 Applied Interactive Programming2 DHTML Example: Avalon  hypothetical web page – Avalon Books  the word “Avalon” appears at the top of the page  “Avalon” descends to a certain point then stops  the word “Books” slides out from behind “Avalon”, moves a certain distance, then stops  3 images appear at certain points on the page, one after another

ECA 225 Applied Interactive Programming3 DHTML Example: Avalon cont …  page will contain 5 objects, each inside a tag, each with a unique id  the word “Avalon”  the word “Books”  first image  second image  third image AVALON

ECA 225 Applied Interactive Programming4 DHTML Example: Avalon cont …  using DHTML we will:  place each object at specific coordinates on the page  set the stacking order of some of the objects  control visibility  move the objects a designated distance  page should be Cross Browser Compatible for NS4, NS6, NS7, IE4, IE5, IE6, Firefox

ECA 225 Applied Interactive Programming5 CSS Review  absolute positioning  positioned in relation to the parent element  stacking order with z-index  the higher the number, the higher on the stack #elem1{ position:absolute; left:200px; top: 25px; } #elem1{ z-index: 3; }

ECA 225 Applied Interactive Programming6 CSS Review cont …  visibility  an object can be hidden, but still take up space on a page  display  an object can be hidden and take up no space on the page #elem1{ visibility: hidden } #elem1{ display: none; }

ECA 225 Applied Interactive Programming7 DOM Review  3 major DOM’s are often incompatible  NS4  uses a property called layers document.layers.avalon  IE  uses a property called all document.all.avalon  W3C  uses a method named getElementById( ) document.getElementById( ‘avalon’ )

ECA 225 Applied Interactive Programming8 Cross Browser Compatibility  DHTML code must  determine which DOM the browser supports  run the correct code supported by that browser, without generating errors  2 approaches  browser detection  object detection

ECA 225 Applied Interactive Programming9 Browser detection  navigator.appName  returns the name of the browser  navigator.appVersion  returns additional information about the browser alert( navigator.appName) // returns “Microsoft Internet Explorer” alert( navigator.appVersion) // returns “4.0(compatible; MSIE 6.0; Windows XP)”

ECA 225 Applied Interactive Programming10 Object detection  code to determine which DOM is supported  test which reference name is recognized  variables will contain true or false, which will be used in subsequent functions var NS4DOM = document.layers ? true : false; var IEDOM = document.all ? true : false; var W3CDOM = document.getElementById ? true : false;

ECA 225 Applied Interactive Programming11 Object detection strategies  page branching  create separate pages for each browser  location.href loads a new URL into the browser if( NS4DOM ) location.href = “ns4_index.htm”; else if( IEDOM ) location.href = “ie_index.htm”; else if( W3CDOM ) location.href = “w3_index.htm”;

ECA 225 Applied Interactive Programming12 Object detection strategies cont …  internal branching  each piece of DHTML code is enclosed in if statements if( NS4DOM ) var elem1 = document.layers.element1.left; if( IEM ) var elem1 = document.all.element1.style.left; if( W3CDOM ) var elem1 = document.getElementById(‘element1’).style.left;

ECA 225 Applied Interactive Programming13 Object detection strategies cont …  API  Application Programming Interface  external file ( *.js ) that contains functions to resolve compatibility issues  link from web page to external file  do not place directly in root directory

ECA 225 Applied Interactive Programming14 API for Avalon  API will contain the following:  commands to determine which DOM is supported by the browser  a function to resolve the differences among each DOM and it’s way of referencing objects  a function to place objects at specific locations  a function to move an object  a function that returns the left value of an object  a function that returns the top value of an object  a function to hide an object  a function to make an object visible

ECA 225 Applied Interactive Programming15 API for Avalon cont …  function to resolve references to objects var NS4DOM = document.layers ? true : false; var IEDOM = document.all ? true : false; var W3CDOM = document.getElementById ? true : false; function getObject(id){ if(NS4DOM) ref = "document.layers." + id; else if(IEDOM) ref = "document.all." + id; else if(W3CDOM) ref = "document.getElementById('" + id + "')"; var object = eval(ref); return object; }

ECA 225 Applied Interactive Programming16 API for Avalon cont …  getObject( ) takes one parameter, the id of the object we want to reference  eval( ) method takes a string as an argument and creates a reference to the actual object  getObject( ) returns the reference to the object  eg, if we pass getObject the ‘avalon’ id W3CDOM returns document.layers.avalon IEDOM returns document.all.avalon W3CDOM returns document.getElementById(‘avalon’)

ECA 225 Applied Interactive Programming17 Accessing CSS properties  different DOM’s reference properties in different ways NS4DOM object.left // returns 300 IEDOM object.style.left // returns 300px object.style.pixelleft // returns 300 W3CDOM object.style.left // returns 300px

ECA 225 Applied Interactive Programming18 Accessing CSS properties cont …  to drop the ‘px’ use parseInt( ) NS4DOM object.left // returns 300 IEDOM parseInt(object.style.left) // returns 300 object.style.pixelLeft // returns 300 W3CDOM parseInt(object.style.left) // returns 300

ECA 225 Applied Interactive Programming19 Accessing CSS properties cont …  layering using z-index NS4DOM object.zIndex IEDOM and W3CDOM object.style.zIndex

ECA 225 Applied Interactive Programming20 Accessing CSS properties cont …  visibility  display NS4DOM object.visibility = ‘show’ IEDOM and W3CDOM object.style.visibility = “visible” NS4DOM object.display = ‘hide’ IEDOM and W3CDOM object.style.display = “hidden”

ECA 225 Applied Interactive Programming21 API functions  Placing objects  function to position each object on the page using left and top properties function placeIt(id, x, y){ var object = getObject(id); if(NS4DOM) object.moveTo(x, y); else if( IEDOM || W3CDOM ){ object.style.left = x; object.style.top = y; }

ECA 225 Applied Interactive Programming22 Web page functions  function named placeObjects( ) called from an onLoad event handler function placeObjects(){ placeIt("avalon",175,10); placeIt("books",175,10); placeIt("AB",230,40); placeIt("Fiction",5,5); placeIt("NFiction",475,5); moveAvalon( ); }

ECA 225 Applied Interactive Programming23 API functions  Animating objects – uses 3 functions  function to move an object from its current position a specified distance function shiftIt(id, dx, dy){ var object = getObject(id); if(NS4DOM){ object.moveBy(dx, dy); } else if( IEDOM ){ object.style.pixelLeft = object.style.pixelLeft + dx; object.style.pixelTop = object.style.pixelTop + dy; } else if( W3CDOM ){ object.style.left = parseInt(object.style.left) + dx; object.style.top = parseInt(object.style.top) + dy; }

ECA 225 Applied Interactive Programming24 API functions  Animating objects – uses 3 functions  a function to find the value of the object’s left property function xCoord(id){ var object = getObject(id); if( NS4DOM ) xc = object.left; else if( IEDOM ) xc = object.style.pixelLeft; else if( W3CDOM ) xc = parseInt(object.style.left); return xc; }

ECA 225 Applied Interactive Programming25 API functions  Animating objects – uses 3 functions  a function to find the value of the object’s top property function yCoord(id){ var object = getObject(id); if( NS4DOM ) yc = object.top; else if( IEDOM ) yc = object.style.pixelTop; else if( W3CDOM ) yc = parseInt(object.style.top); return yc; }

ECA 225 Applied Interactive Programming26 Web page functions  function named moveAvalon( ) to move the object down the page a specified distance function moveAvalon(){ var y = yCoord("avalon"); if( y <= 275 ){ shiftIt("avalon",0,4); shiftIt("books",0,4); setTimeout("moveAvalon( )", 20); } else{ moveBooks( ); }

ECA 225 Applied Interactive Programming27 Web page functions  function named moveBooks( ) to move the object to the right a specified distance function moveBooks(){ var x = xCoord("books"); if( x <= 320 ){ shiftIt("books",4,0); setTimeout("moveBooks( )", 20); } else{ showObjects( ); }

ECA 225 Applied Interactive Programming28 API functions  Showing objects  2 functions to change the visibility of an object function hideIt(id){ var object = getObject(id); if( NS4DOM ) object.visibility="hide"; else if( IEDOM || W3CDOM ) object.style.visibility="hidden"; } function showIt(id){ var object = getObject(id); if( NS4DOM ) object.visibility="show"; else if( IEDOM || W3CDOM ) object.style.visibility="visible"; }

ECA 225 Applied Interactive Programming29 Web page functions  function named showObjects( ) to change the visibility property function showObjects(){ setTimeout("showIt('AB')",500); setTimeout("showIt('Fiction')",1000); setTimeout("showIt('NFiction')",1500); }