Graphics Reference
In-Depth Information
6. Interval Logic • The setInterval() method takes two parameters. The
first is the name of the function that will be regularly called. Make sure that
you pass a reference to the function by using parentheses to avoid calling
the function. The time is given in milliseconds so that the 1.000 value is ideal
for the second-by-second call. Next, implement the code to determine the
time and adjust the bars. For this, extend the update() method as follows:
// Register Interval
setInterval(update, 1000);
// Function to be called per interval
function update() {
try {
// Get Date
var currentDate = new Date();
var hoursInPixel = currentDate.getHours()
*(400/24) + "px";
var minutesInPixel = currentDate.getMinutes()
*(400/60) + "px";
var secondsInPixel = currentDate.getSeconds()
*(400/60) + "px";
// Update Hours
var hourBar = sym.$("hourBar");
hourBar.css( "width", hoursInPixel );
// Update Minutes
var minuteBar = sym.$("minuteBar");
minuteBar.css( "width", minutesInPixel );
// Update Seconds
var secondBar = sym.$("secondBar");
secondBar.css( "width", secondsInPixel );
} catch (error) {
console.log("Error: ", error);
}
}
 
Search WWH ::




Custom Search