17
Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from W3schools. Edited by Guoliang Liu, Only for Course CSc2320 at GSU CS Department

Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from

Embed Size (px)

Citation preview

Page 1: Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from

Events and AnimationsCSc 2320Fall 2014

Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from W3schools.Edited by Guoliang Liu, Only for Course CSc2320 at GSU CS Department

Page 2: Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from

In this chapterEvents in JavaScriptAnimation

Page 3: Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from

Events handlerElement with attribute onclick.Onclick with call functionFunction defined in your script or

library.

Page 4: Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from

How the event worksOne example

Page 5: Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from

How the annoying pop up window worksAdvertisement pages

Page 6: Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from

Problems with event handlerMore than one handler with one

element

Page 7: Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from

AnimationThe principles of animationsDisplay n frames or pictures per

second

Page 8: Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from

AnimationControl time with JavaScript

Page 9: Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from

AnimationSet the timerFunction

◦SetTimeout(function, time);◦E.g.,

Page 10: Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from

AnimationTime in a function

Page 11: Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from

AnimationDefine function inside functions

Page 12: Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from

AnimationStop the timer

◦Use function clearTimeout(timer);◦E.g.,

Page 13: Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from

AnimationCreate repeating timer

◦Use function setInterval(function, time);

Stop repeating timer◦Use function clearInterval(timer);◦E.g.,

Page 14: Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from

AnimationPicture animations

Page 15: Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from

AnimationPicture animations(cont.)

Page 16: Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from

AnimationAnother example

Page 17: Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from

Bonus homeworkDo an animation.

◦Make one object moving in a circle repeatedly. E.g., like a soccer ball moving a circle in

the grass ground.

◦Due on 11/26/2014