CS 142 Lecture Notes: Events

Slides:



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

Programming Club IIT Kanpur. Work environment Before you begin coding,always set up your work environment to your needs IDE Notepad++ Sublime Text 2.
DOM and timers CS Problems with JavaScript JavaScript is a powerful language, but it has many flaws:  the DOM can be clunky to use  the same code.
More javascript. Where is the cursor? (similar to my example at end of last ppt)
CS 142 Lecture Notes: FormsSlide 1 Draggable Rectangle #div1 { position: absolute; }...
 x (x 2  0) 1. True2. False.  x (3x + 2 = 12) 1. True2. False.
Generalized De Morgan’s Theorem Lecture L5.4 Section 5.1.
Canvas, SVG, Workers Doncho Minkov Telerik Corporation
CS 174: Web Programming April 9 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
JQuery CS 268. What is jQuery? From their web site:
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
JS: Document Object Model (DOM)
JavaScript Lecture 6 Rachel A Ober
Banners - HTML A banner is a zip-package containing a HTML file, CSS file, and optionally JavaScript file and assets in a asset directory. The banner is.
Lab 3: Language Structures User Interface Lab: GUI Lab Sep. 9 th, 2014.
CSE 190: Internet E-Commerce Lecture 5. Exam Material Lectures 1-4 (Presentation Tier) –3-tier architecture –HTML –Style sheets –Javascript –DOM –HTTP.
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.
JS Basics 1 Lecture JavaScript - Basics. JS Basics 2 What is JavaScript JavaScript is a “simple”, interpreted, programming language with elementary object-
TABLES AND VALUES Section 1.5. Open Sentence Equation.
CS346 Javascript -3 Module 3 JavaScript Variables.
CS 142 Lecture Notes: EventsSlide 1 Access to Event Object ● event variable (HTML): ● Passed as argument to function (DOM/Firefox): element.onclick = mouseClick;
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Dialog boxes in JavaScript Events in JavaScript – What are they – “Which events are there?” – “How do I register event handlers to an HTML element?” –
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
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.
Web Technologies Lecture 8 JQuery. “A fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax.
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
Lab 5: More on Events and Introduction to the Canvas Tag User Interface Lab: GUI Lab Sep. 23 rd, 2013.
Creating Databases Example using Google Maps API + file creation. Dollar sign problem. Classwork/Homework: [catch up]. Work on final project.
Build in Objects In JavaScript, almost "everything" is an object.
CSE 102 Introduction to Web Design and Programming
CSS Rule Selector Declaration Block Value Attribute Name body {
HTML & teh internets.
CS 371 Web Application Programming
JavaScript - Errors & Exceptions Handling
Simple Javascript Example
JavaScript Event Handling.
CGS 3066: Web Programming and Design Spring 2016
setInterval window.setInterval (statement, interval);
Getting web pages First we need to get the webpage by issuing a HTTP request. The best option for this is the requests library that comes with Anaconda:
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript.
Introduction to Computer Graphics with WebGL
Introduction to DOM.
البرمجة بلغة الفيجول بيسك ستوديو
CS 142 Lecture Notes: Events
Functions, Part 2 of 2 Topics Functions That Return a Value
Simple Javascript Example
CS105 Introduction to Computer Concepts
Web Programming Language
LING 408/508: Computational Techniques for Linguists
Progress <progress value="22" max="100"></progress>
Style properties in JavaScript
Simple Javascript Example
Simple Canvas Example Your browser doesn’t support canvases var canvas = document.getElementById("canvas1"); var context.
For this assignment, copy and past the XHTML to a notepad file with the .html extension. Then add the code I ask for to complete the problems.
Javascript Events / keycodes
Advanced DHTML, Dynamic CSS
Pertemuan 13 JavaScript.
Tutorial 10: Programming with javascript
The <script> Tag
JAVASCRIPT HOW TO PROGRAM -2
MicroContributions.
CS105 Introduction to Computer Concepts JavaScript
JavaScript – Let’s Draw!
Presentation transcript:

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

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

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"; function mouseUp(event) {

Cleaner Implementation <body> <div id="div1">Drag Me!</div> <div id="div2">Drag Me Too!</div> <script type="text/javascript" src="dragger.js" /> <script type="text/javascript"> //<![CDATA[ new Dragger("div1"); new Dragger("div2"); //]]> </script> </body>} CS 142 Lecture Notes: Events

CS 142 Lecture Notes: Events 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) { 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: Events

CS 142 Lecture Notes: Events 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: Events

Which Element Gets Event? <body> <table> <tr> <td>xyz</td> </tr> </table> </body> Click on this CS 142 Lecture Notes: Events

CS 142 Lecture Notes: Cookies