js to achieve star flash effects

js to achieve star flash effects

This article example shares the specific code of js to achieve the star flash effect for your reference. The specific content is as follows

The effect is as follows

Ideas:

1. Prepare a picture of stars
2. Create multiple stars (you can use for loop)
3. Find the width and height of the visible web page clientWidth, clientHeight
4. Set the random coordinates of the stars using Math.random()
5. To set the scale of the star, you can use scale in CSS
6. Set the star scaling delay frequency animationDelay
7. Add animation to the stars (the stars rotate when the mouse moves)

The code is as follows

 <style>
 *{
  margin: 0;
  padding: 0;
  list-style: none;
 }

 body{
  background-color: #000;
 }

 span{
  width: 30px;
  height: 30px;
  background: url("../images_js/star.png") no-repeat;
  position: absolute;
  background-size:100% 100%;
  animation: flash 1s alternate infinite;
 }

 @keyframes flash {
  0%{opacity: 0;}
  100%{opacity: 1;}
 }

 span:hover{
  transform: scale(3, 3) rotate(180deg) !important;
  transition: all 1s;
 }
 </style>
</head>
<body>
<script>
 window.onload = function () {
 // 1. Find the screen size var screenW = document.documentElement.clientWidth;
 var screenH = document.documentElement.clientHeight;

 // 2. Dynamically create stars for(var i=0; i<150; i++){
  // 2.1 Create stars var span = document.createElement('span');
  document.body.appendChild(span);

  // 2.2 Random coordinates var x = parseInt(Math.random() * screenW);
  var y = parseInt(Math.random() * screenH);
  span.style.left = x + 'px';
  span.style.top = y + 'px';

  // 2.3 Random scaling var scale = Math.random() * 1.5;
  span.style.transform = 'scale('+ scale + ', ' + scale + ')';

  // 2.4 frequency var rate = Math.random() * 1.5;
  span.style.animationDelay = rate + 's';
 }
 }
</script>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • JS implements the star rating function example code (two methods)
  • js code to light up the star rating and get the parameters
  • js star rating effect
  • How to achieve star scoring effect in js
  • Star rating function implemented by js
  • JavaScript + CSS Many websites use the function of selecting stars to implement the scoring function
  • JS implements the star function of evaluation
  • js to achieve flying into the stars special effects code
  • AngularJS implements star rating function
  • JavaScript to achieve random display of star effects

<<:  Tutorial on installing MySQL 5.7.18 using RPM package

>>:  How to build php-nginx-alpine image from scratch in Docker

Recommend

A detailed explanation of how React Fiber works

Table of contents What is React Fiber? Why React ...

JavaScript imitates Jingdong carousel effect

This article shares the specific code for JavaScr...

Detailed tutorial on installing mysql-8.0.20 under Linux

** Install mysql-8.0.20 under Linux ** Environmen...

JS realizes the card dealing animation

This article example shares the specific code of ...

React event binding details

Table of contents Class component event binding F...

Solution for installing opencv 3.2.0 in Ubuntu 18.04

Download opencv.zip Install the dependencies ahea...

How to quickly modify the host attribute of a MySQL user

When you log in to MySQL remotely, the account yo...

JavaScript history object explained

Table of contents 1. Route navigation 2. History ...

HTML drawing user registration page

This article shares the specific implementation c...

How to create LVM for XFS file system in Ubuntu

Preface lvm (Logical Volume Manager) logical volu...

JavaScript implements password box input verification

Sometimes it is necessary to perform simple verif...

Detailed tutorial for installing MySQL 8.0.11 compressed version under win10

After reinstalling my computer recently, I downlo...