one of the most cooler things most programmer have thought of is how to create a simple timing event how to make ads appear at some interval in your page how to make a certain picture pop out after spending some time on a o page today am going to teach you how to create a timing event using javascript with a simple example
The window object allows execution of code at specified time intervals.
These time intervals are called timing events.
The two key methods to use with JavaScript are:
setTimeout(function, milliseconds)
Executes a function, after waiting a specified number of milliseconds.
setInterval(function, milliseconds)
Same as setTimeout(), but repeats the execution of the function continuously.
below is a simple that displays a digital watch after 5seconds of page opening
<!DOCTYPE html>
<html>
<body>
<p>welcome</p>
<p id="demo"></p>
<script>
var myVar = setInterval(myTimer, 5000);
function myTimer() {
var d = new Date();
document.getElementById("demo").innerHTML = d.toLocaleTimeString();
}
</script>
</body>
</html>
when writing you script you start by creating and setting a time interval for the funtion in your script to run
var myVar = setInterval(myTimer, 5000); this is five seconds since time is measured in milliseconds
then add a function that does whatever you want in javascript in this case a digital time
CREATE A TIMING EVENT IN HTML
Location:
Nigeria
0 comments:
Post a Comment