CS 142 Lecture Notes: EventsSlide 1 Access to Event Object ● event variable (HTML): ● Passed as argument to function (DOM/Firefox): element.onclick = mouseClick;

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

© Park University, 2006 Creating an Interactive Web Page with DHTML and JavaScript Park University.
5.1 JavaScript Execution Environment
Bring Life to Your Web Pages with JavaScript and HTML5 Ole Ildsgaard Hougaard -
The jQuery library. What is jQuery ? A javascript lightweight library Is very easy to use Is powerful Is cross-browser compatible Downloadable from jQuery.com,
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
The Document Object Model (DOM) 1 JavaScript is an object-based language—that is, it’s based on manipulating objects by changing each object’s properties.
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
More javascript. Where is the cursor? (similar to my example at end of last ppt)
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Cos 381 Day 12.
CS 142 Lecture Notes: FormsSlide 1 Draggable Rectangle #div1 { position: absolute; }...
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Cos 381 Day 9.
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.
JavaScript Client Side scripting. Client-side Scripts Client-side scripts, which run on the user’s workstation can be used to: Validate user inputs entered.
DHTML - Introduction Introduction to DHTML, the DOM, JS review.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 Dynamic Documents With JavaScript.
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.
JavaScript Lecture 6 Rachel A Ober
Lecture 11 – DOM Scripting SFDV3011 – Advanced Web Development Reference: 1.
CSC 298 Windows Forms.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming DOM.
DOM Events. JS Events Outline About Events – Introduction – Registering events – Getting information from events Event order/phases – Preventing default.
Code for touch, get mouse and pen for free Pointer API captures pen motion, passing coordinates to Ink API Ink API helps render and stores motion.
Chapter 5 © 2005 by Addison Wesley Longman, Inc JavaScript Execution Environment - The JavaScript Window object represents the window in which the.
CS 142 Lecture Notes: EventsSlide 1 Access to Event Object ● event variable (HTML): ● Passed as argument to function (DOM/Firefox): element.onclick = mouseClick;
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.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
CSS1 Dynamic HTML Objects, Collections & Events. CSS2 Introduction Dynamic HTML treats HTML elements as objects. Element’s parameters can be treated as.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming DHTML Example.
CS50 Week 9 Sam Green ’
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 12.
DOM Events. JS Events Outline About Events – Introduction – Registering events – Getting information from events Event order/phases – Preventing default.
 Scripts that execute in response to some event  User clicking on something  Script does NOT execute as part of page loading  DOM facilities like.
JavaScript Functions A function is a block of code that can be reused. It is similar to a method in Java. It consists of a function name, an argument.
Dr. Ahmet Cengizhan Dirican BIL 374 Internet Technologies 5. JavaScript and HTML Documents.
5 th and 4 th ed: some from chapters 9, 12, 13 SY306 Web and Databases for Cyber Operations Slide Set #8: Dynamic HTML.
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
1 Javascript CS , Spring What is Javascript ? Browser scripting language  Dynamic page creation  Interactive  Embedded into HTML pages.
Chapter 6 © 2014 by Pearson Education Introduction Def: A dynamic HTML document is one whose tag attributes, tag contents, or element style properties.
Events CS The keyword this  all JavaScript code actually runs inside of an object  by default, code runs inside the global window object  all.
HTML DOM The Document Object Model is a Javascript class that defines HTML elements as objects. It supports … properties methods events Image from
Dr. Ahmet Cengizhan Dirican BIL 374 Internet Technologies 6. Dynamic Documents With JavaScript.
Chapter 6 Dynamic Documents with JavaScript. © 2006 Pearson Addison-Wesley. All rights reserved Introduction Def: A dynamic HTML document is.
JAVASCRIPT A quick review. True False ■The DOM is a standardized way of referring to parts of a Web page. ■TRUE ■In the DOM, attributes have their own.
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
CSE 154 LECTURE 10: MORE EVENTS. Problems with reading/changing styles Click Me HTML window.onload = function() { document.getElementById("clickme").onclick.
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,
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
6.1 Introduction 6.2 Element Positioning
THE DOM.
JavaScript Print slides by Sean Boyle, with overall content based on material provided by Dan Bogaard, from:
Introduction to JavaScript Events
JavaScript Events.
CS 142 Lecture Notes: Events
CSE 154 Lecture 11: More Events.
JavaScript and HTML Documents
CS 142 Lecture Notes: Events
COP3530- Data Structures Javascript
Introduction to DHTML, the DOM, JS review
JavaScript Basics Topics Review Important Methods Writing Functions
5.1 JavaScript Execution Environment
JavaScript Intro.
JavaScript Event Handling For Interaction and Casual Games
6.1 Introduction 6.2 Positioning Elements
Presentation transcript:

CS 142 Lecture Notes: EventsSlide 1 Access to Event Object ● event variable (HTML): ● Passed as argument to function (DOM/Firefox): element.onclick = mouseClick; function mouseClick(evt) {... x = evt.clientX;... } ● Global variable (DOM/IE): element.onclick = mouseClick; function mouseClick() {... x = window.event.clientX;... }

CS 142 Lecture Notes: EventsSlide 2 Draggable Rectangle #div1 { position: absolute; }... <div id="div1" onmousedown="mouseDown(event);" onmousemove="mouseMove(event);" onmouseup="mouseUp(event);">Drag Me!

Slide 3 Dragging Application isMouseDown = false; function mouseDown(event) { prevX = event.clientX; prevY = event.clientY; isMouseDown = true; } function mouseMove(event) { if (!isMouseDown) { return; } var element = document.getElementById("div1"); element.style.left = (element.offsetLeft + (event.clientX - prevX)) + "px"; element.style.top = (element.offsetTop + (event.clientY - prevY)) + "px"; prevX = event.clientX; prevY = event.clientY; } function mouseUp(event) { isMouseDown = false; }

CS 142 Lecture Notes: EventsSlide 4 Cleaner Implementation Drag Me! Drag Me Too! //<![CDATA[ new Dragger("div1"); new Dragger("div2"); //]]> }

CS 142 Lecture Notes: EventsSlide 5 Dragger.js, part 1 function Dragger(id) { this.isMouseDown = false; this.element = document.getElementById(id); var obj = this; this.element.onmousedown = function(event) { obj.mouseDown(event); } Dragger.prototype.mouseDown = function(event) { var obj = this; this.oldMoveHandler = document.body.onmousemove; document.body.onmousemove = function(event) { obj.mouseMove(event); } this.oldUpHandler = document.body.onmouseup; document.body.onmouseup = function(event) { obj.mouseUp(event); } this.prevX = event.clientX; this.prevY = event.clientY; this.isMouseDown = true; }

CS 142 Lecture Notes: EventsSlide 6 Dragger.js, part 2 Dragger.prototype.mouseMove = function(event) { if (!this.isMouseDown) { return; } this.element.style.left = (this.element.offsetLeft + (event.clientX - this.prevX)) + "px"; this.element.style.top = (this.element.offsetTop + (event.clientY - this.prevY)) + "px"; this.prevX = event.clientX; this.prevY = event.clientY; } Dragger.prototype.mouseUp = function(event) { this.isMouseDown = false; document.body.onmousemove = this.oldMoveHandler; document.body.onmouseup = this.oldUpHandler; }

CS 142 Lecture Notes: EventsSlide 7 Which Element Gets Event? xyz Click on this

CS 142 Lecture Notes: CookiesSlide 8