| 1 |
# `web-sys`: A `requestAnimationFrame` Loop |
| 2 |
|
| 3 |
[View full source code][code] or [view the compiled example online][online] |
| 4 |
|
| 5 |
[online]: https://rustwasm.github.io/wasm-bindgen/exbuild/request-animation-frame/ |
| 6 |
[code]: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/request-animation-frame |
| 7 |
|
| 8 |
This is an example of a `requestAnimationFrame` loop using the `web-sys` crate! |
| 9 |
It renders a count of how many times a `requestAnimationFrame` callback has been |
| 10 |
invoked and then it breaks out of the `requestAnimationFrame` loop after 300 |
| 11 |
iterations. |
| 12 |
|
| 13 |
## `Cargo.toml` |
| 14 |
|
| 15 |
You can see here how we depend on `web-sys` and activate associated features to |
| 16 |
enable all the various APIs: |
| 17 |
|
| 18 |
```toml |
| 19 |
{{#include ../../../examples/request-animation-frame/Cargo.toml}} |
| 20 |
``` |
| 21 |
|
| 22 |
## `src/lib.rs` |
| 23 |
|
| 24 |
```rust |
| 25 |
{{#include ../../../examples/request-animation-frame/src/lib.rs}} |
| 26 |
``` |