Dr. Ahmet Cengizhan Dirican BIL 374 Internet Technologies 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.
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.
Computer Science 103 Chapter 4 Advanced JavaScript.
MORE Cascading Style Sheets (The Positioning Model)
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.
Copyright © Texas Education Agency, All rights reserved. 1 Web Technologies Website Development with Dreamweaver.
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.
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.
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.
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.
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.
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: 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.
JavaScript - A Web Script Language Fred Durao
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.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.
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.
XP New Perspectives on Macromedia Dreamweaver MX 2004 Tutorial 6 1 Creating Dynamic Pages.
Chapter 6 Dynamic Documents with JavaScript. © 2006 Pearson Addison-Wesley. All rights reserved Introduction Def: A dynamic HTML document is.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
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.
Mimi Opkins.  One of the major benefits of using CSS is that you’re not forced to lay your sites out in tables.  The layout possibilities of CSS give.
6.1 Introduction 6.2 Element Positioning
Understanding Dynamic HTML Barry Sosinsky Valda Hilley
Using DHTML to Enhance Web Pages
Chapter 2 – Introduction to the Visual Studio .NET IDE
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:

Dr. Ahmet Cengizhan Dirican BIL 374 Internet Technologies 6. Dynamic Documents With JavaScript

1-2 Internet Technologies Dr. Ahmet Cengizhan Dirican Introduction Using DOM, JavaScript can change the document in which it is embedded Elements can be move Style can be changed Visibility can be changed

1-3 Internet Technologies Dr. Ahmet Cengizhan Dirican Element Positioning CSS provides powerful tools to position elements in a web page The position property specifies the position mode Value is absolute or 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

1-4 Internet Technologies Dr. Ahmet Cengizhan Dirican 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 element

1-5 Internet Technologies Dr. Ahmet Cengizhan Dirican 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 text

1-6 Internet Technologies Dr. Ahmet Cengizhan Dirican 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 elements 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)

1-7 Internet Technologies Dr. Ahmet Cengizhan Dirican Element Visibility Example showHide.html illustrates hiding and showing an element by manipulating the visibility property 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

1-8 Internet Technologies Dr. Ahmet Cengizhan Dirican Changing Colors and Fonts Colors and font properties can be manipulated through the style property of an element

1-9 Internet Technologies Dr. Ahmet Cengizhan Dirican Changing Colors Example dynColors.html illustrates setting background and foreground colors 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

1-10 Internet Technologies Dr. Ahmet Cengizhan Dirican Changing Fonts The dynLink example illustrates changing font properties using JavaScript 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

1-11 Internet Technologies Dr. Ahmet Cengizhan Dirican 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 components The mouseover and mouseout events are used to control this The value property of the ‘help’ box is used to change the content

1-12 Internet Technologies Dr. Ahmet Cengizhan Dirican 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 an 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 dynamically

1-13 Internet Technologies Dr. Ahmet Cengizhan Dirican 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 points

1-14 Internet Technologies Dr. Ahmet Cengizhan Dirican Reacting to a Mouse Click The anywhere.html example is another example using mouse location information The example uses mousedown and mouseup events to drive the action The position and visibility of an element are manipulated by the event handler

1-15 Internet Technologies Dr. Ahmet Cengizhan Dirican 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

1-16 Internet Technologies Dr. Ahmet Cengizhan Dirican 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

1-17 Internet Technologies Dr. Ahmet Cengizhan Dirican 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

1-18 Internet Technologies Dr. Ahmet Cengizhan Dirican Example moveText.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

1-19 Internet Technologies Dr. Ahmet Cengizhan Dirican Dragging and Dropping Elements Example dragNDrop.html illustrates dynamically modifying event handlers in order to provide dragging and dropping functionality 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