Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to delay start animation? #163

Closed
aha74 opened this issue Aug 28, 2017 · 7 comments
Closed

How to delay start animation? #163

aha74 opened this issue Aug 28, 2017 · 7 comments

Comments

@aha74
Copy link

aha74 commented Aug 28, 2017

Hi! First off, great plugin! I was wondering if you can help me with delaying the animation. For example, I would like the animation to start one or two seconds after the page loads. Thanks in advance.

@kottenator
Copy link
Owner

kottenator commented Aug 30, 2017

Hi, @aha74! I appreciate your words, thanks ;)

To delay the animation you could:

el.circleProgress({
  // any options, but value is 0 at the beginning
  value: 0
});

setTimeout(() => el.circleProgress('value', realValue), 2000);

In addition, you could wait until your circle appears in browser's viewport - see #8.

@aha74
Copy link
Author

aha74 commented Aug 30, 2017

Thanks for the response. Sorry, but I'm a newb at this. Where would I put it in this code.

<script>
  var circle = $('#circle').circleProgress({
    value: 0.71,
    fill: {
      gradient: ['#002856', '#67b2e8']
    },
    size: 150
  });

  circle.resizable()
    .on('resizestop', function() {
      circle.circleProgress();
    });

  circle.on('circle-animation-progress', function(e, p, v) {
    var obj = $(this).data('circle-progress'),
      ctx = obj.ctx,
      s = obj.size,
      sv = (100 * v).toFixed(),
      fill = obj.arcFill;

    ctx.save();
    ctx.font = "bold " + s / 2.5 + "px sans-serif";
    ctx.textAlign = 'center';
    ctx.textBaseline = 'middle';
    ctx.fillStyle = fill;
    ctx.fillText(sv, s / 2, s / 2);
    ctx.restore();
  });
</script>

Also, how would I add an "%" at the end of the numbers, yet make it smaller then the number?
Sorry for all the questions.
Thanks in advance.

@kottenator
Copy link
Owner

Where would I put it in this code

In you HTML, below the library inclusion. Or in one of your JS files.

how would I add an "%" at the end of the numbers

Change sv = (100 * v).toFixed() to sv = (100 * v).toFixed() + '%'

yet make it smaller then the number

That would be pretty hard in this case. You can use another approach - render the text in HTML, not in canvas (just add some <div> which would contain the numbers, and position it absolutely over the circle).

@aha74
Copy link
Author

aha74 commented Aug 31, 2017

Thanks for all the help. My apologies, but what I mean is, where in my current script, would I put the timer delay script you provided.

@kottenator
Copy link
Owner

kottenator commented Aug 31, 2017

Here's a snippet for you.

@aha74
Copy link
Author

aha74 commented Aug 31, 2017

You are the man!!! Thank you!

@kottenator
Copy link
Owner

You're welcome ;) I'm closing this ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants