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
The Important Thing About By. The Important Thing About ******** The important thing about ***** is *****. It is true s/he can *****, *****, and *****.
Advertisements

CS 142 Lecture Notes: EventsSlide 1 Access to Event Object ● event variable (HTML): ● Passed as argument to function (DOM/Firefox): element.onclick = mouseClick;
P u t y o u r h e a d o n m y s h o u l d e r.
IS660Z Programming Games Using Visual Basic Overview of Cannonball.
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,
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
More javascript. Where is the cursor? (similar to my example at end of last ppt)
Labs for week 7 Exploring simple mouse-paint And Primitive base changer.
CS 140 Lecture 5 Professor CK Cheng 10/10/02. Part I. Combinational Logic 1.Spec 2.Implementation K-map: Sum of products Product of sums.
CS 142 Lecture Notes: FormsSlide 1 Draggable Rectangle #div1 { position: absolute; }...
CS Oct 2006 Chap 6. Functions General form; type Name ( parameters ) { … return value ; }
 x (x 2  0) 1. True2. False.  x (3x + 2 = 12) 1. True2. False.
CS 142 Lecture Notes: JavascriptSlide 1 Simple Javascript Example sum = 0; for (i = 1; i < 10; i++) { sum += i*i; }
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.
Generalized De Morgan’s Theorem Lecture L5.4 Section 5.1.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
Chapter 6 JavaScript and AJAX. Objectives Explain the purpose and history of JavaScript Describe JavaScript features Explain the event-driven nature of.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 Dynamic Documents With JavaScript.
JavaScript Lecture 6 Rachel A Ober
Lecture Set 13 Drawing Mouse and Keyboard Events Part B – Mouse and Keyboard Events.
TABLES AND VALUES Section 1.5. Open Sentence Equation.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
Dialog boxes in JavaScript Events in JavaScript – What are they – “Which events are there?” – “How do I register event handlers to an HTML element?” –
The Web Wizard’s Guide To DHTML and CSS Chapter 6 Understanding Events.
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.
Basic Definitions of Set Theory Lecture 24 Section 5.1 Fri, Mar 2, 2007.
School of Computing and Information Systems CS 371 Web Application Programming JavaScript - DOM Modifying the Page from within.
1 Javascript CS , Spring What is Javascript ? Browser scripting language  Dynamic page creation  Interactive  Embedded into HTML pages.
A: A: double “4” A: “34” 4.
Programming games using Visual Basic Detecting a position on top/within a rectangle, near a point, past a line Mouse events.
Pemrograman Berbasis Web
Events Event Handling in JavaScript SoftUni Team Technical Trainers Software University
Events CS The keyword this  all JavaScript code actually runs inside of an object  by default, code runs inside the global window object  all.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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.
Lab 5: More on Events and Introduction to the Canvas Tag User Interface Lab: GUI Lab Sep. 23 rd, 2013.
CS 142 Lecture Notes: JavascriptSlide 1 Simple Javascript Example sum = 0; for (i = 1; i < 10; i++) { sum += i*i; }
Chapter 6 Dynamic Documents with JavaScript. © 2006 Pearson Addison-Wesley. All rights reserved Introduction Def: A dynamic HTML document is.
CSE 154 LECTURE 10: MORE EVENTS. Problems with reading/changing styles Click Me HTML window.onload = function() { document.getElementById("clickme").onclick.
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,
CS 106A, Lecture 27 Final Exam Review 1
6.1 Introduction 6.2 Element Positioning
CS 371 Web Application Programming
Introduction to Programming the WWW I
CS 142 Lecture Notes: Events
Web Systems Development (CSC-215)
CSE 154 Lecture 11: More Events.
CS 142 Lecture Notes: Events
Name Not Precise Enough
Nate Brunelle Today: Functions again, Scope
More programming with "Processing"
Progress <progress value="22" max="100"></progress>
Simple Canvas Example Your browser doesn’t support canvases var canvas = document.getElementById("canvas1"); var context.
Objectives: Graph (and write) inequalities on a number line.
CLICK TO START.
Compiler Construction
Mouse Input.
CHAPTER 6 EVENTS. CHAPTER 6 EVENTS WHAT IS AN EVENT?
CLICK TO START.
JavaScript Event Handling For Interaction and Casual Games
CS150 Introduction to Computer Science 1
6.1 Introduction 6.2 Positioning Elements
If there is any case in which true premises lead to a false conclusion, the argument is invalid. Therefore this argument is INVALID.
Programming II Vocabulary Review Loops & functions
If there is any case in which true premises lead to a false conclusion, the argument is invalid. Therefore this argument is INVALID.
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!

CS 142 Lecture Notes: EventsSlide 3 Dragging Application isMouseDown = false; function mouseDown(event) { prevX = event.clientX; prevY = event.clientY; isMouseDown = true; } function mouseMove(event) { if (!isMouseDown) { return; } 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); this.element.onmousedown = this.wrap(this, "mouseDown"); } Dragger.prototype.wrap = function(obj, method) { return function(event) { obj[method](event); } Dragger.prototype.mouseDown = function(event) { this.oldMoveHandler = document.body.onmousemove; document.onmousemove = this.wrap(this, "mouseMove"); this.oldUpHandler = document.body.onmouseup; document.onmouseup = this.wrap(this, "mouseUp"); 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.onmousemove = this.oldMoveHandler; document.onmouseup = this.oldUpHandler; }

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

CS 142 Lecture Notes: EventsSlide 8