How to make a Simple HTML5 Canvas Loader

How to make a Simple HTML5 Canvas Loader
by Janeth Kent Date: 11-12-2013 html5 web loader coding programming

Let's code an HTML5 Canvas Loader: 


  1. <canvas id="demo" height="400" width="400" style="background:#000;" />


  1. var canvas = document.getElementById('demo');
  2. var context = canvas.getContext('2d');
  3. var start = new Date();
  4. var lines = 16,
  5. cW = context.canvas.width,
  6. cH = context.canvas.height;
  8. var draw = function() {
  9. var rotation = parseInt(((new Date() - start) / 1000) * lines) / lines;
  11. context.clearRect(0, 0, cW, cH);
  12. context.translate(cW / 2, cH / 2);
  13. context.rotate(Math.PI * 2 * rotation);
  14. for (var i = 0; i < lines; i++) {
  16. context.beginPath();
  17. context.rotate(Math.PI * 2 / lines);
  18. context.moveTo(cW / 10, 0);
  19. context.lineTo(cW / 4, 0);
  20. context.lineWidth = cW / 30;
  21. context.strokeStyle = "rgba(255,255,255," + i / lines + ")";
  22. context.stroke();
  23. }
  24. context.restore();
  25. };
  26. window.setInterval(draw, 1000 / 30);
by Janeth Kent Date: 11-12-2013 html5 web loader coding programming hits : 6977  
Janeth Kent

Janeth Kent

Licenciada en Bellas Artes y programadora por pasión. Cuando tengo un rato retoco fotos, edito vídeos y diseño cosas. El resto del tiempo escribo en MA-NO WEB DESIGN AND DEVELOPMENT.


Related Posts

Loading images by resolution with HTML5

Normally the way to load images in HTML is through the img element to which we pass as a parameter the URL of the image to load. But since HTML5…

How to make your own custom cursor for your website

When I started browsing different and original websites to learn from them, one of the first things that caught my attention was that some of them had their own cursors,…

8 benefits of having a website for your business

At this moment, the Internet is a phenomenon that is sweeping the world. It has been able to interconnect millions of users all over the planet. People have made the…

Open source web design tools alternatives

There are many prototyping tools, user interface design tools or vector graphics applications. But most of them are paid or closed source. So here I will show you several open…

How to access webcam and grab an image using HTML5 and Javascript

We often use webcams to broadcast video in real time via our computer. This broadcast can be viewed, saved and even shared via the Internet. As a rule, we need…

How to Send Email from an HTML Contact Form

In today’s article we will write about how to make a working form that upon hitting that submit button will be functional and send the email (to you as a…

Looping through a matrix with JavaScript

We were already talking about how to multiply arrays in JavaScript and we realised that we had not explained something as simple as traversing an array with Javascript. So we…

How to multiply matrices in JavaScript

It may seem strange to want to know how to multiply matrices in JavaScript. But we will see some examples where it is useful to know how to perform this…

JavaScript Formatting Date Tips

Something that seems simple as the treatment of dates can become complex if we don't take into account how to treat them when presenting them to the user. That is…

Top tools for UX design and research

This article is a compilation of the "ux tools" I have tested in recent years. I've separated the tools by categories, although I recommend you to take a look at all…

How to make a multilingual website without redirect

Today, we're going to talk about how to implement a simple language selector on the basic static website, without the need of any backend or database calls or redirection to…

Starting with Bootstrap-Vue step by step

Today we will show you how to use BootstrapVue, describe the installation process and show basic functionality. The project’s based on the world's most popular CSS framework - Bootstrap, for building…

We use our own and third-party cookies to improve our services, compile statistical information and analyze your browsing habits. This allows us to personalize the content we offer and to show you advertisements related to your preferences. By clicking "Accept all" you agree to the storage of cookies on your device to improve website navigation, analyse traffic and assist our marketing activities. You can also select "System Cookies Only" to accept only the cookies required for the website to function, or you can select the cookies you wish to activate by clicking on "settings".

Accept All Only sistem cookies Configuration