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 : 7573  
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

Let's create a Color Picker from scratch with HTML5 Canvas, Javascript and CSS3

HTML5 Canvas is a technology that allows developers to generate real-time graphics and animations using JavaScript. It provides a blank canvas on which graphical elements, such as lines, shapes, images…

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 create a .onion domain for your website

The dark web, a hidden network accessed through the Tor browser, offers enhanced privacy and anonymity for websites. To establish a presence on the dark web, you can create a…

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…