Actuellement, lorsque nous souhaitons faire patienter l’internaute en attendant que le contenu charge, nous utilisions des fichiers GIF de loading. En effet d’un point de vue UX, quand le chargement prends un peu de temps (quelques secondes) il est préférable d’afficher une image de loading que rien du tout. L’internaute est ainsi au courant que quelque chose va arriver.
Ancienne utilisation du GIF loading
Dans mon cas j’utilisais le célèbre icône GIF, que j’insèrais dans mon CSS via la balise background-image.
L’inconvénient est que nous chargeons une ressource en plus, et qu’il fallait avoir l’icône dans différentes taille en fonction de notre besoin.
La deuxième option a été d’utiliser un loading en base64 toujours via la propriété CSS background-image. Plus aucune ressource n’était chargée. Par contre insérer un base64 dans notre fichier CSS, rends un peu plus difficile sa lecture, comme vous pouvez le constater. Via la propriété zoom, il est possible d’agrandir ou diminuer la taille du GIF.
.loadingimg { display: block; padding: 23px; height: 23px; width: 23px; zoom: 1; background-repeat: no-repeat; background-image: url(data:image/gif;base64,R0lGODlhMAAwAPcAAAAAABMTExUVFRsbGx0dHSYmJikpKS8vLzAwMDc3Nz4+PkJCQkRERElJSVBQUFdXV1hYWFxcXGNjY2RkZGhoaGxsbHFxcXZ2dnl5eX9/f4GBgYaGhoiIiI6OjpKSkpaWlpubm56enqKioqWlpampqa6urrCwsLe3t7q6ur6+vsHBwcfHx8vLy8zMzNLS0tXV1dnZ2dzc3OHh4eXl5erq6u7u7vLy8vf39/n5+f///wEBAQQEBA4ODhkZGSEhIS0tLTk5OUNDQ0pKSk1NTV9fX2lpaXBwcHd3d35+foKCgoSEhIuLi4yMjJGRkZWVlZ2dnaSkpKysrLOzs7u7u7y8vMPDw8bGxsnJydvb293d3eLi4ubm5uvr6+zs7Pb29gYGBg8PDyAgICcnJzU1NTs7O0ZGRkxMTFRUVFpaWmFhYWVlZWtra21tbXNzc3V1dXh4eIeHh4qKipCQkJSUlJiYmJycnKampqqqqrW1tcTExMrKys7OztPT09fX19jY2Ojo6PPz8/r6+hwcHCUlJTQ0NDg4OEFBQU9PT11dXWBgYGZmZm9vb3Jycnp6en19fYCAg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cU0wwClC7QxCUEmILFrQjA8oedAmJjQzKIcNMOXahpQGoEtr2lBgTShTGjiQCog0QgHRRVjiQiccnALQpVIM8QTRQl0zBDSSDNuDrZwwIEJAu2hbSP0TpbHMccAWtAe3BlkSQTscqguBRN8sKoIjbihAaoVMbnRDRu0C0FxORwzQcJopaKBG26IcChFI7GrsFoTUHCyQCY00ggSe6TYhRvsyiKxuhsfI9YsbjTSzJQh1WKuNKgUdAzCKwukgsuNLLuVFhOY68ajGW+c9F8f9KxZWpbIMkQowxKkMccFWYKEGxvc7BMMsxwT4thXo2lCliQWM6LGKtPaJkIipA8c2t4T/bHHHv4CbjhBAQEAOw==); background-position: center center; }
Exemple avec un zoom 1 et 0.5 :
Spinner loading full CSS
Une troisième option s’offre à vous, vous pouvez créer un icône loading plus customisable (couleur, taille, …) avec seulement du CSS et la propriété animation.
Voici par exemple ce qu’il est possible de faire :
La structure HTML n’est pas compliquée :
<div class="demo "> <div class="custom-loading-spinner"></div> Quis enim aut eum diligat quem metuat, aut eum a quo se metui putet? Coluntur tamen simulatione dumtaxat ad tempus. Quod si forte, ut fit plerumque, ceciderunt, tum intellegitur quam fuerint inopes amicorum. Quod Tarquinium dixisse ferunt, tum exsulantem se intellexisse quos fidos amicos habuisset, quos infidos, cum iam neutris gratiam referre posset. </div>
Voici maintenant le CSS :
.demo { width: 200px; margin: 0 auto; position: relative; text-align: justify; } .custom-loading-spinner { cursor: progress; position: absolute; width: 100%; height: 100%; } .custom-loading-spinner::before { content: ""; position: absolute; width: 100%; height: 100%; z-index: 10001; overflow: hidden; background: #0b0b0b; opacity: 0.6; } .custom-loading-spinner::after { box-sizing: border-box; z-index: 10002; content: ""; position: absolute; top: 50%; left: 50%; margin: -25px 0 0 -25px; border: 3px solid #f3f3f3; border-top: 3px solid #3498db; border-radius: 50%; width: 50px; height: 50px; animation: custom-loading 1s linear infinite; } @keyframes custom-loading { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
Explication du code
La première partie .custom-loading-spinner::before permet de rajouter un overlay sur notre contenu. Il couvrira la totalité du contenu avec une opacité de 0.6. Voici le rendu :
La deuxième partie .custom-loading-spinner::after génère notre cercle blanc avec un bord bleu. en utilisant les propriétés border et border-radius. On attribue une animation qui s’appelle custom-loading. Pour l’instant le bord bleu se trouve en haut (border-top) :
La dernière partie permet de définir de ce que va faire l’animation css. Dans notre cas nous allons animer notre cercle en lui appliquant une rotation de 360°, le bord bleu tournera. Sur la capture ci dessous vous constatez que le bord bleu se trouve sur la droite :