Bring Life to Your Web Pages with JavaScript and HTML5 Ole Ildsgaard Hougaard -

Slides:



Advertisements
Similar presentations
JavaScript Chapter 6 Note new scoring. spin.js (page 67) function spin() function spin() { var obj_style = document.getElementById("d1").style; var obj_style.
Advertisements

1 Web Site Design Overview of the Internet Cookie Setton.
© Park University, 2006 Creating an Interactive Web Page with DHTML and JavaScript Park University.
CS 142 Lecture Notes: EventsSlide 1 Access to Event Object ● event variable (HTML): ● Passed as argument to function (DOM/Firefox): element.onclick = mouseClick;
Bring Life to Your Web Pages with JavaScript and HTML5 Part 2 Ole Ildsgaard Hougaard -
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
Chapter 6 © 2012 by Addison Wesley Longman, Inc Introduction Def: A dynamic HTML document is one whose tag attributes, tag contents, or element.
Introduction to JavaScript Module 1 Client Side JS Programming M-GO Sponsored By
The Web Warrior Guide to Web Design Technologies
Georgia Institute of Technology JavaScript part 2 Barb Ericson Georgia Institute of Technology May 2006.
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.
Information Technology Center Hany Abdelwahab Computer Specialist.
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.
UNIT 6 JAVASCRIPT EVENT HANDLERS &WEB BROWSERS DETECTION.
DHTML - Introduction Introduction to DHTML, the DOM, JS review.
HTML Forms/Events (Instructor Lesson) The Event model HTML Forms Custom Events 1.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Chapter 19: Adding JavaScript
Unobtrusive JavaScript
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Lecture 11 – DOM Scripting SFDV3011 – Advanced Web Development Reference: 1.
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.
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.
CITS1231 Web Technologies JavaScript and Document Object Model.
What is Java Script? An extension to HTML. An extension to HTML. Allows authors to incorporate some functionality in their web pages. (without using CGI.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
JavaScript, Fourth Edition
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
1.NET Web Forms Client-Side JavaScript © 2002 by Jerry Post.
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
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.
CSS1 Dynamic HTML Objects, Collections & Events. CSS2 Introduction Dynamic HTML treats HTML elements as objects. Element’s parameters can be treated as.
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
COS 125 DAY 20. Agenda Assignment 8 not corrected yet Assignment 9 posted  Due April 16 New course time line Discussion on Scripts 
Web Programming Java Script & jQuery Web Programming.
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.
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.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
Chapter 10 Dynamic HTML (DHTML) JavaScript, Third Edition.
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.
4.1. Manage and maintain JavaScript Update the UI by using JavaScript. Understanding JavaScript and Coding Essentials.
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,
COM621: Advanced Interactive Web Development Lecture 6 – JavaScript (cont.)
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.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
6.1 Introduction 6.2 Element Positioning
THE DOM.
JavaScript and HTML Simple Event Handling 11-May-18.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Human Computer Interaction
The Internet and HTML Code
Web Development & Design Foundations with HTML5 7th Edition
JavaScript and HTML Simple Event Handling 19-Sep-18.
DHTML Javascript Internet Technology.
DHTML Javascript Internet Technology.
Introduction to DHTML, the DOM, JS review
Introduction to Programming and JavaScript
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:

Bring Life to Your Web Pages with JavaScript and HTML5 Ole Ildsgaard Hougaard -

Web and Multimedia HTML 1 had pictures, but nothing else. HTML 2, 3 and 4? The same(!) What do we do instead? Plug-ins. Possible plug-ins: Windows Media Player, Apple QuickTime, Adobe Flash De-facto standard: Flash but… Ole Ildsgaard Hougaard -

HTML5 New tags:,,,,, … Multimedia support:, New APIs: canvas, drag-and-drop support Ole Ildsgaard Hougaard -

JavaScript Not Java! A scripting language (whatever that means) A dynamic language (whatever that means) Used to Java or C#? – JavaScript can be quite familiar – JavaScript can be a bit odd – JavaScript can be downright weird

Why JavaScript? Saves server roundtrips Saves bandwidth Saves server processing power (Almost) standard No installation required Powerful language

Why not JavaScript? Slow (in some browsers) Might be switched off Not completely standard Yet another language to learn Strange language

The simple stuff var x = 7; x = x + x; alert(x); No type Part of browser environment

Simple HTML page Simple

Other simple HTML page Simple var x = 7; x = x + x; alert(x);

The window object var x = 7; x = x + x; window.alert(x); window is the global object.

Extending window window.x = 7; x = x + x; window.alert(window.x); x is a field in the window object.

What does this do? window.x = 7; x = x + x; window.alert(window.y);

Arrays and for-loops var numbers = [1, 2, 4, 8]; for(var i = 0; i < numbers.length; i++) { alert(numbers[i]); }

Functions A function is like a method in other languages The syntax is like Java except you don't have types Defining a function means defining a method on the this object Functions are first-class citizens

Defining and calling a function function showDouble(x) { var y = x + x; alert(y); } var x = 7; showDouble(x); showDouble is a method on the this object y is a local variable

Anonymous functions function (x) { var y = x + x; alert(y); }

Calling an anonymous function var x = 7; (function (x) { var y = x + x; alert(y); })(x);

Saving a function in a variable showDouble = function (x) { var y = x + x; alert(y); } var x = 7; showDouble(x); showDouble is a field on the window object What is the difference between methods and fields containing functions?

Exercises 1.Create an HTML page with a JavaScript program that adds the first 10 numbers and shows the result. 2.(Optional) Create a JavaScript function that takes a number (call it n) and returns a function. The returned function should take a number (call it m) and return m*n.

Interacting with the page The primary interaction with the browser is through the document The document is the HTML document that the browser is rendering The document is modelled in an object model It's the Document Object Model (DOM)

The DOM The document object model represents all elements of the HTML/CSS as an object Main objects are: window and document window is used to interact with the browser window document is used to interact with HTML/CSS

Changing the title this.x = 7; x = x + x; document.title = x;

Dragging an image

Body of the document

Let's get stylish #dragArea { width: 800px; height: 600px; border: 1px solid black; position: relative; overflow: hidden; } #image { position: absolute; }

Events DOM has an event model Examples of events: – onload – onclick, onmousedown, onmousemove, onmouseup – onscroll – onsubmit

Setting an event handler In the HTML: … In JavaScript code: document.body.onload = init; … but when?

Finding elements function init() { this.dragArea = document.getElementById("dragArea"); this.image = document.getElementById("image"); //… }

Centering the picture function init() { //… var areaWidth = dragArea.clientWidth; var areaHeight = dragArea.clientHeight; var imgWidth = image.clientWidth; var imgHeight = image.clientHeight; image.style.left = (areaWidth - imgWidth) / 2; image.style.top = (areaHeight - imgHeight) / 2; //… }

Let's make a simpler version function init() { //… dragArea.onclick = move; } function move(event) { // Internet Explorer hack: if (!event) event = window.event; image.style.left = event.clientX - dragArea.offsetLeft; image.style.top = event.clientY - dragArea.offsetTop; };

Exercises 3.Create an HTML page with a button. Show the sum of the first 10 numbers when the button is pressed. 4.Add a field to the page and 5.Create an HTML page with a gallery of images (whatever you can find on the net or your own harddisk). There should be a "previous" and a "next" link to flip through the images. (Hint: You can set the "src" attribute of an image element.)