Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- element we are going to animate -->
- <div id="box"> Ninja </div>
- <script type="text/javascript">
- function animateIt(elementId) {
- //inside the animateIt() function, we get a reference to that element.
- var elem = document.getElementById(elementId);
- //establishes a counter to keep track of animation ticks (steps)
- var tick = 0;
- //creates and starts an interval timer given a callback function that will be invoked every 10ms.
- //For 100 ticks, it will adjust the position of the element.
- var timer = setInterval(function() {
- if (tick < 100) {
- elem.style.left = elem.style.top = tick + "px";
- tick++;
- }
- else {
- clearInterval(timer);
- assert(tick == 100, "Tick is accessed via a closure");
- assert(elem, "Element also accessed via closure");
- assert(timer, "Timer reference also obtained via closure");
- }
- }, 10);
- }
- animateIt('box');
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement