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: 

HTML

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

Js

  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;
  7.  
  8. var draw = function() {
  9. var rotation = parseInt(((new Date() - start) / 1000) * lines) / lines;
  10. context.save();
  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++) {
  15.  
  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 : 6189  
 
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 END DEVELOPMENT.

 
 
 

Related Posts

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…

Bootstrap 5 beta2. What offers?

Since the release of the Bootstrap 4 is three years, in this article we will present what is new in the world’s most popular framework for building responsive, mobile-first sites.…

Graphic design and its impact on Web Development

In today's article we will explain the concept of graphic design, its fundamentals and what it brings into web development. Graphic design is applied to everything visual, believe or not,…

Creating simple CSS spinner-loader

In today's article we will show you how to animate a basic loader that spins when some predefined action is defined, such as loading an image. That can be used…

Understanding LCP, CLS, FID. All about Core Web Vitals in Google Search Console

A few months ago we talked about certain Google metrics that were displayed in Search Console. The reason for writing another post on this topic is that Google has changed…

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