setInterval window.setInterval (statement, interval);

Slides:



Advertisements
Similar presentations
Programming Club IIT Kanpur. Work environment Before you begin coding,always set up your work environment to your needs IDE Notepad++ Sublime Text 2.
Advertisements

Very quick intro HTML and CSS. Sample html A Web Title.
Part 5 Introduction to CSS. CSS Display - Block and Inline Elements A block element is an element that takes up the full width available, and has a line.
With CSS, a color is most often specified by: a HEX value - like "#ff0000" an RGB value - like "rgb(255,0,0)" a color name - like "red“ Example h1.
Class four: the box model and positioning. is an HTML tag which allows you to create an element out of inline text. It doesn’t mean anything! try it:
Today’s objectives Site performance Padding, Margins, Borders
Tutorial 6 Creating Fixed-Width Layouts
Using CSS for Page Layout. Types of HTML Elements Block-Level Element –Creates blocks of content e.g. div, h1..h6, p, ul, ol, li, table, form –They start.
Art 128 Interface Programming 1 In-class Presentation Week 11B.
1 The Structure of a Web Table beginning of the table structure first row of three in the table end of the table structure table cells You do not need.
W. W. Milner JavaScript. W. W. Milner Chapter 1 - Intro Why use JavaScript? Interactivity LiveScript JavaScript Jscript ECMAScript JavaScript is not Java!
Eat Your Words! Creating webpage Layout. CONTENT The Layout of a Webpage HEADER FOOTER Each of these sections represents a ‘div’ (or divider). By linking.
Making a Timer in Alice.
Cascading Style Sheets CSS. CSS Positioning Normal Flow Top -> bottom | left -> right Arranged in the order they appear in the code make room for one.
Cascading Style Sheets CSS. div … Used like a container to group content Gives context to the elements in the grouping Give it a descriptive name with.
Programming Games Review for midterm. Work session. Homework: Prepare for midterm.
Unobtrusive JavaScript
Working with background, images and date object Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 20 – Dynamic HTML: Path, Sequencer and Sprite ActiveX Controls Outline 20.1Introduction 20.2DirectAnimation.
 2001 Deitel & Associates, Inc. All rights reserved. 1 Chapter 20 – Dynamic HTML: Object Model and Collections Outline 20.1Introduction 20.2Object Referencing.
JavaScript – more arrays, images. Image Object and images[] array  Using allows us to display images on webpages. What if we want more control of what.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
Web Foundations WEDNESDAY, NOVEMBER 20, 2013 LECTURE 32: DREAMWEAVER SLIDE SHOW AND GOOGLE MAP.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
JavaScript Challenges Answers for challenges
 Scripts that execute in response to some event  User clicking on something  Script does NOT execute as part of page loading  DOM facilities like.
Web Technologies Beginning Cascading Style Sheets (CSS) 1Copyright © Texas Education Agency, All rights reserved.
SetTimeout()  What if you want to automatically cycle through the pics?  So you don’t have to keep clicking the button to see the next pic  Use the.
Department of Computer Science, Florida State University CGS 3066: Web Programming and Design Spring 2016 CSS Positioning 1.
Adding Javascript How to include javascript in a webpage.
- WE’LL LOOK AT THE POSITION PROPERTY AND HOW CSS RESOLVES CONFLICTS BETWEEN STYLING INSTRUCTIONS The position property; CSS specificity hierarchy.
HTML Elements: Forms and Controls Chapter 9 B. Ramamurthy.
Changing CSS Styles via JavaScript No readings?. 2 Review? You can change the CSS styling of an element with JavaScript Syntax is similar to accessing.
CONCEPTS FOR FLUID LAYOUT Web Page Layout. Essential Questions What challenges do mobile devices present to Web designers? What are the basic concepts.
REEM ALMOTIRI Information Technology Department Majmaah University.
HTML for JavaScript Web Applications
>> Form Data Validation in JavaScript
Introduction to.
Applied Component I Unit II Introduction of java-script
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Loop Lab CSD 340 (Blum).
CSS Layouts: Grouping Elements
Webpage layout using CSS
JavaScript is a programming language designed for Web pages.
Positioning Objects with CSS and Tables
JavaScript functions.
Intro to JavaScript CS 1150 Spring 2017.
Chapter 14: DHTML: Event Model
Cascading Style Sheets (Layout)
JavaScript Functions.
HTML Images CS 1150 Spring 2017.
PAGE LAYOUT - 2.  The div tag equipped with CSS rules produces good looking pages.  With CSS, the div tag can easily be positioned anywhere on the page.
JavaScript Introduction
Positioning.
MORE Cascading Style Sheets (The Positioning Model)
JavaScript & jQuery Timers, Effects, and Animations
Javascript Game Assessment
Tutorial 6 Creating Dynamic Pages
Creating a Webpage with External CSS
Cascading Style Sheets™ (CSS)
HTML Images CS 1150 Fall 2016.
Floating and Positioning
JavaScript Basics Topics Review Important Methods Writing Functions
JavaScript Basics What is JavaScript?
Positioning.
Positioning Objects with CSS and Tables
Cascading Style Sheets
Web Programming and Design
CGS 3066: Web Programming and Design Fall 2019 CSS Part 2
Presentation transcript:

setInterval window.setInterval (statement, interval); Schedules a "statement" to occur every interval milliseconds (1000 milliseconds = 1 second) Statement is often a call to a function (built-in or user-defined)

Do Now: clock.html <script type="text/javascript"> function displayTime () { var element = document.getElementById ("time"); element.innerHTML = Date(); return; } setInterval ('displayTime()', 100); </script> <body> The current time is: <span id="time"></span> </body>

cancelling a timer Timers are actually objects. Can hold the timer information in a variable: var t; // global variable for timer t =setInterval ('displayTime()', 50); </script> <button onclick="clearInterval (t)">Cancel</button>

Create a webpage named countdown.html with: a div element with an id = "countdown" A global variable timeLeft and 3 functions: startCountdown () { prompt user for number of seconds set the global variable timeLeft to that many seconds call setInterval to call countDown() every second countDown () { display the time remaining in the countdown div reduce timeLeft by 1 if timeLeft equals 0, alert "Boom" and cancel timer cancelCountdown () { alert "Cancelled" and cancel timer 2 buttons - one to start and once to cancel

Moving an object Create a div with id="ball" Use CSS to give the div a distinct background, a position: absolute, top: 50px, left: 0px, and a fixed height and width Create a global variable to keep track of the left position Use setInterval to periodically change the div element's left position (will make it move)

<div id="ball"></div> <script type="text/javascript"> var left = 0; function moveBall () { var e = document.getElementById ("ball"); e.style.left = left + "px"; left = left + 1; } setInterval ("moveBall()", 100); </script>

Additional tasks Give the "ball" an image use an <img> tag inside the bouncing div Make the ball "bounce" back and forth when left exceeds the right edge, start subtracting instead of adding to it Add a button to stop/start the ball Add a button to prompt the user for the speed