Reputation: 328
how to convert the following setInterval() to requestAnimationFrame()?
Below is a simple working setInterval model that I'm using.
$(document).ready(function() {
$("#add").click(function() {
$('#result').html(
(parseFloat($('#numA').val()) +
parseFloat($('#numB').val())).toString()
);
});
setInterval(function () {$("#add").click()}, 1000);
});
I've seen one that requires loop (game loop), but my code isn't about gaming. It's about parsing strings.
The documentation is a bit complicated. I've tried some trial-errors, but no success so far.
Thank you for any input.
Upvotes: 0
Views: 253
Reputation: 94131
You need to invoke requestAnimationFrame
repeatedly, for example:
!function frame() {
$('#add').click()
requestAnimationFrame(frame)
}()
Demo: http://jsfiddle.net/nqqfq/6/
Upvotes: 1