PP.requestAnimationFrame

Syntax

requestAnimationFrame(sender, callback: Function);

Parameters

sender. Function execution context.

callback. Function to execute.

Description

The requestAnimationFrame method performs specified function with minimum delay.

Comments

This method is used to draw elements' animation.

Example

To execute the example, add a link to PP.js scenario file to HTML page. Find real duration of the delay that occurs as the result of the requestAnimationFrame method:

var startTime; // Time before delay
// Function performed after delay
function func() {
    // Get the current time in milliseconds
    var endDate = new Date();
    console.log("Delay end time, ms: " + endDate.getTime());
    console.log("Delay duration: " + (endDate.getTime() - startTime));
};
// Get the current time in milliseconds
startDate = new Date();
var startTime = startDate.getTime();
console.log("Delay start time, ms: " + startTime);
for (var i = 0; i < 999; i++) {
    // Call empty delay
    PP.requestAnimationFrame.call(window, function () {});
};
// Call delay
PP.requestAnimationFrame.call(window, func);

After executing the example the browser console displays duration of 1,000 delays:

Delay start time, ms: 1363869880983
1000
Delay end time, ms: 1363869880992
Delay duration: 9
 

Thus, duration of a single delay tends to zero.

See also:

PP