CMPE 280 Web UI Design and Development September 14 Class Meeting

Slides:



Advertisements
Similar presentations
Introduction to Web Design Lecture number:. Todays Aim: Introduction to Web-designing and how its done. Modelling websites in HTML.
Advertisements

© Park University, 2006 Creating an Interactive Web Page with DHTML and JavaScript Park University.
Bring Life to Your Web Pages with JavaScript and HTML5 Ole Ildsgaard Hougaard -
CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
CSCI 3100 Tutorial 6 Web Development Tools 1 Cuiyun GAO 1.
CSS Internet Engineering Spring 2014 Bahador Bakhshi CE & IT Department, Amirkabir University of Technology.
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
Today CSS HTML A project.
Presenter: James Huang Date: Sept. 26,  Introduction  Basics  Lists  Links  Forms  CSS 2.
Very quick intro HTML and CSS. Sample html A Web Title.
Cascading Style Sheets. CSS stands for Cascading Style Sheets and is a simple styling language which allows attaching style to HTML elements. CSS is a.
Web Pages and Style Sheets Bert Wachsmuth. HTML versus XHTML XHTML is a stricter version of HTML: HTML + stricter rules = XHTML. XHTML Rule violations:
กระบวนวิชา CSS. What is CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML 4.0 to.
Computer Science 103 Chapter 4 Advanced JavaScript.
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.
CS 174: Web Programming February 26 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
UNIT 6 JAVASCRIPT EVENT HANDLERS &WEB BROWSERS DETECTION.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Internet Mark-up Languages CO32036 Part Lecture: Elementary JavaScript.
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.
Administration, Coverage, Review. Exam Administration Midterm exam is in class from 5:15 – 6:30PM on Thursday Feb 20 th. The exam is open book and open.
Programming Games Show project. Refresher on coordinates. Scaling, translation. HTML5 logo. Refresher on animation. Bouncing ball. Homework: Do your own.
CS134 Web Design & Development Cascading Style Sheets (CSS) Mehmud Abliz.
CS 174: Web Programming September 30 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 174: Web Programming October 7 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 174: Web Programming October 5 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
C H 07: M ORE A BOUT HTML Tharith Sriv. O UTLINE You have already learnt almost everything in HTML. In this chapter, you will learn more about:  An HTML.
More on Events Some More Events Image Rollover Objects Select-Option List Control 1.
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.
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.
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,
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.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.
Creating Web Documents CSS examples (do more later) Lab/Homework: Read chapters 15 & 16. Work on Project 3, do postings.
6.1 Introduction 6.2 Element Positioning
THE DOM.
CSS.
That Gauge is COOL! 
Week 3: Introduction to Javascript
CSS Layouts: Grouping Elements
CMPE 280 Web UI Design and Development September 12 Class Meeting
Week 4: Introduction to Javascript
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
CMPE 280 Web UI Design and Development September 21 Class Meeting
Using Cascading Style Sheets Module B: CSS Structure
Cascading Style Sheets (Layout)
Web Systems & Technologies
Chapter 7 Page Layout Basics Key Concepts
CMPE 280 Web UI Design and Development February 20 Class Meeting
Web Development & Design Foundations with HTML5 8th Edition
Cascading Style Sheets
IS333: MULTI-TIER APPLICATION DEVELOPMENT
Basics of Web Design Chapter 7 Page Layout Basics Key Concepts
Web Programming A different world! Three main languages/tools No Java
DynamicHTML Cascading Style Sheet Internet Technology.
CMPE 280 Web UI Design and Development September 4 Class Meeting
DynamicHTML Cascading Style Sheet Internet Technology.
CMPE 280 Web UI Design and Development February 7 Class Meeting
E-commerce Applications Development
Web Programming and Design
Week 5: Recap and Portfolio Site
Web Programming and Design
Web Programming and Design
6.1 Introduction 6.2 Positioning Elements
© 2017, Mike Murach & Associates, Inc.
CMPE 280 Web UI Design and Development September 5 Class Meeting
CMPE 280 Web UI Design and Development February 21 Class Meeting
Presentation transcript:

CMPE 280 Web UI Design and Development September 14 Class Meeting Department of Computer Engineering San Jose State University Fall 2017 Instructor: Ron Mak www.cs.sjsu.edu/~mak

JavaScript Animation Animate objects on the HTML canvas. Use an animation loop to perform transformations: translations: move objects rotations: rotate objects scaling: grow and shrink objects

Temporary Coordinate System Transformations are actually performed on the coordinate system. Draw the object in the transformed coordinate system. Common sequence: Save the current coordinate system and create a temporary coordinate system. Draw the object. Restore the coordinate system.

Scaling Grow or shrink an object by scaling the axes of the coordinate system. Apply a multiplication factor to each axis. con1.drawImage(image, CANVAS_X, CANVAS_Y, IMAGE_W, IMAGE_H); con2.save(); con2.scale(1.2, 0.8); con2.drawImage(image, CANVAS_X, CANVAS_Y, con2.restore(); Save the current coordinate system and begin a temporary system. Restore the saved coordinate system. animation/transform.html

Scaling, cont’d

Rotation Rotation is clockwise about the canvas origin. Specify the rotation amount in radians. animation/transform.html con3.save(); con3.rotate(Math.PI/8); con3.drawImage(image, CANVAS_X, CANVAS_Y, IMAGE_W, IMAGE_H); con3.restore();

Translation To rotate around the center of an object, first translate the canvas origin to the object center. con4.save(); con4.translate(100, 100); con4.rotate(Math.PI/8); con4.drawImage(image, -IMAGE_W/2, -IMAGE_H/2, IMAGE_W, IMAGE_H); con4.restore(); animation/transform.html

Animation Loop To animate, repeatedly call a drawing function. Set the frame rate. Games typically run between 10 and 30 frames per second. Call setInterval(function, delay) function: the drawing function to call repeatedly delay: the number of milliseconds between calls 100 = 10 frames/second 50 = 20 frames/second

Animated Rotation <body onload = "init()"> animation/rotate.html <body onload = "init()"> <h1>Rotations</h1> <canvas id = "canvas" height = "200" width = "200"> <p>Canvas not supported!</p> </canvas> </body>

Animated Rotation, cont’d const CANVAS_X = 50; const CANVAS_Y = 50; const CANVAS_W = 200; const CANVAS_H = 200; const IMAGE_W = 100; const IMAGE_H = 100; var con; var image; var angle = 0; function init() { con = document.getElementById("canvas") .getContext("2d"); image = new Image(); image.src = "images/bristol.png"; setInterval(draw, 50); } animation/rotate.html

Animated Rotation, cont’d animation/rotate.html function draw() { con.strokeStyle = "black"; con.fillStyle = "white"; con.fillRect(0, 0, CANVAS_W, CANVAS_H); con.strokeRect(0, 0, CANVAS_W, CANVAS_H); angle += 0.25; if (angle > 2*Math.PI) angle = 0; con.save(); con.translate(100, 100); con.rotate(angle); con.drawImage(image, -IMAGE_W/2, -IMAGE_H/2, IMAGE_W, IMAGE_H); con.restore(); } First clear the canvas Translate, then rotate.

Moving Objects To animate moving an object, draw it in a slightly different location during each call of the drawing function. Remember to clear the canvas first, otherwise the object is “smeared” across the canvas.

Moving Objects, cont’d function draw() { animation/bounce.html function draw() { con.fillRect(0, 0, CANVAS_W, CANVAS_H); con.strokeRect(0, 0, CANVAS_W, CANVAS_H); con.drawImage(image, x, y, IMAGE_W, IMAGE_H); x += dx; y += dy; // Bounce off a wall if ((x < 0) || (x > RIGHT)) dx = -dx; if ((y < 0) || (y > BOTTOM)) dy = -dy; } Clear the canvas.

Keyboard Animation Control You can use the keyboard to control animation. Set the event handler for the document’s onkeydown event. animation/arrowkeys.html const KEY_SPACE = 32; const KEY_LEFT = 37; const KEY_UP = 38; const KEY_RIGHT = 39; const KEY_DOWN = 40; ... document.onkeydown = updateKeys;

Keyboard Animation Control, cont’d animation/arrowkeys.html function updateKeys(event) { key = event.keyCode; switch(key) { case KEY_LEFT: dx -= 5; break; case KEY_RIGHT: dx += 5; break; case KEY_UP: dy -= 5; break; case KEY_DOWN: dy += 5; break; case KEY_SPACE: dx = dy = 0; break; default: break; }

Keyboard Animation Control, cont’d animation/arrowkeys.html function draw() { con.fillRect(0, 0, CANVAS_W, CANVAS_H); con.strokeRect(0, 0, CANVAS_W, CANVAS_H); con.drawImage(image, x, y, IMAGE_W, IMAGE_H); x += dx; y += dy; // Wrap around if (x < 0) x = CANVAS_W; else if (x > CANVAS_W) x = 0; if (y < 0) y = CANVAS_H; else if (y > CANVAS_H) y = 0; }

Mouse Events onclick onmouseleave oncontextmenu onmousemove ondblclick onmouseover onmouseup onmouseout onmousedown onmouseenter Demo

Mouse Animation Control animation/mouse.html function init() { var canvas = document.getElementById("canvas"); con = canvas.getContext("2d"); con.fillStyle = "white"; con.strokeStyle = "lightgray"; con.lineWidth = 1; con.strokeRect(0, 0, CANVAS_W, CANVAS_H); canvas.onmouseenter = mouseEnter; canvas.onmouseleave = mouseLeave; canvas.onmousemove = mouseMove; } Assign event handlers.

Mouse Animation Control, cont’d function mouseEnter(event) { con.lineWidth = 3; con.strokeStyle = "white"; con.strokeRect(0, 0, CANVAS_W, CANVAS_H); con.strokeStyle = "red"; } function mouseLeave(event) con.lineWidth = 4; con.strokeStyle = "lightgray"; con.lineWidth = 1; animation/mouse.html

Mouse Animation Control, cont’d function mouseMove(event) { var mouseX = event.pageX - CANVAS_LEFT; var mouseY = event.pageY - CANVAS_TOP; con.lineWidth = 3; con.fillStyle = "white"; con.fillRect(0, 0, CANVAS_W, CANVAS_H); con.strokeRect(0, 0, CANVAS_W, CANVAS_H); con.lineWidth = 5; con.beginPath(); con.moveTo(CANVAS_W/2, CANVAS_H/2); con.lineTo(mouseX, mouseY); con.stroke(); con.closePath(); } Map page coordinates to canvas coordinates. animation/mouse.html

Mouse Animation Control, cont’d <style type = "text/css"> #canvas { position: absolute; left: 50px; top: 100px; } </style> const CANVAS_LEFT = 50; const CANVAS_TOP = 100; animation/mouse.html <canvas id = "canvas" height = "200" width = "200"> <p>Canvas not supported!</p> </canvas>

Animated Menus Done entirely with CSS and JavaScript. No canvas required! Demo

Animated Menus: Example 1 <body>     <h1>Shakespeare's Plays</h1>     <div>         <a href="menu1.html" class="menuLink">Comedies</a>         <ul class="menu" id="menu1">             <li><a href="pg1.html">All's Well That Ends Well</a></li>             <li><a href="pg2.html">As You Like It</a></li>             <li><a href="pg3.html">Love's Labour's Lost</a></li>             <li><a href="pg4.html">The Comedy of Errors</a></li>         </ul>     </div>         <a href="menu2.html" class="menuLink">Tragedies</a>         <ul class="menu" id="menu2">             <li><a href="pg5.html">Anthony & Cleopatra</a></li>             <li><a href="pg6.html">Hamlet</a></li>             <li><a href="pg7.html">Romeo & Juliet</a></li>         </div>         <a href="menu3.html" class="menuLink">Histories</a>         <ul class="menu" id="menu3">             <li><a href="pg8.html">Henry IV, Part 1</a></li>             <li><a href="pg9.html">Henry IV, Part 2</a></li> </body> menus/menu1.html

Animated Menus: Example 1, cont’d menus/menu1.js window.onload = init; function init()  {     var allLinks = document.getElementsByTagName("a");          for (var i = 0; i < allLinks.length; i++) {         if (allLinks[i].className == "menuLink") {             allLinks[i].onclick = toggleMenu;         }     } }

Animated Menus: Example 1, cont’d menus/menu1.js function toggleMenu(event)  {     var startMenu    = this.href.lastIndexOf("/") + 1;     var stopMenu     = this.href.lastIndexOf(".");     var thisMenuName = this.href.substring(startMenu, stopMenu);          var thisMenuStyle = document.getElementById(thisMenuName).style;     if (thisMenuStyle.display == "block") {         thisMenuStyle.display = "none";     }     else {         thisMenuStyle.display = "block";     event.preventDefault(); } Toggle between invisible and visible. ul.menu { display: none; list-style-type: none; margin-top: 5px; } Initially invisible. menus/menu1.css

Animated Menus: Example 2 We can make the animated menus fancier with a better CSS file and better JavaScript. Anonymous functions to toggle visibility: menuParent.onmouseout = function() { thisMenuStyle.display = "none"; }; menuParent.onmouseover = function() thisMenuStyle.display = "block"; Semicolon required! Semicolon required! Demo

Review for Midterm #1 Closed book exam. Old-fashioned paper and pencil. Combination of multiple-choice, short answer, and programming snippets. Programming will be graded on understanding concepts, not syntax. Be sure to understand the concepts presented in the lectures. Be sure to understand the assignments.

Review for Midterm #1, cont’d How the web works Client browsers and web servers HTTP request and response Static and dynamic web pages Basic “naked” HTML 5 Headers and paragraphs Lists and tables Images and links Forms: input from text, buttons, and menu selections

Review for Midterm #1, cont’d node.js and Express Process form data Generate dynamic web pages Functional specification Functional and nonfunctional requirements Use cases

Review for Midterm #1, cont’d CSS 3 style sheets Selectors Style rules Layout and formatting Document Object Model (DOM) JavaScript Variables and functions Events and event handlers Input validation

Review for Midterm #1, cont’d HTML 5 canvas Drawing operations Animation