Solved

jQuery animation faster

Posted on 2016-11-09
1
16 Views
Last Modified: 2016-11-23
How do I control the speed of the following animation?

<script>
(function() {
  var requestAnimationFrame1 = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
                              window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
  window.requestAnimationFrame = requestAnimationFrame1;
})();
 var canvas1 = document.getElementById('canvas1');
 var context1 = canvas1.getContext('2d');
 var x1 = canvas1.width / 2;
 var y1 = canvas1.height / 2;
 var radius1 = 63;
 var endPercent1 = 90;
 var curPerc1 = 0;
 var counterClockwise1 = false;
 var circ1 = Math.PI * 2;
 var quart1 = Math.PI / 2;

 context1.lineWidth = 13;
 context1.strokeStyle = '#d32128';
 context1['imageSmoothingEnabled'] = false;       /* standard */
    context1['mozImageSmoothingEnabled'] = false;    /* Firefox */
    context1['oImageSmoothingEnabled'] = false;      /* Opera */
    context1['webkitImageSmoothingEnabled'] = false; /* Safari */
    context1['msImageSmoothingEnabled'] = false;     /* IE */



 function animate1(current) {
     //context.clearRect(0, 0, canvas.width, canvas.height);
     context1.beginPath();
     context1.arc(x1, y1, radius1, -(quart1), ((circ1) * current) - quart1, false);
     context1.stroke();
     curPerc1++;
     if (curPerc1 < endPercent1) {
         requestAnimationFrame(function () {
             animate1(curPerc1 / 100)
         });
     }
 }

</script>

Open in new window

0
Comment
Question by:rgranlund
1 Comment
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41880966
Change line 33.

To make it faster add more than 1
To make it slower add less than 1

Faster
curPerc1+=2; // twice as fast

Open in new window

Slower
curPerc1+=0.5 /half as fast

Open in new window

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now