JS realizes the card dealing animation

JS realizes the card dealing animation

This article example shares the specific code of JS to implement the card dealing animation for your reference. The specific content is as follows

Watch the demo first

Game build preparation

1. Prepare 52 cards
2. A tablecloth
3. The editing tool is Visual Code

Technical Overview

1. Object Operation
2. Data Operation
3.JS animation
4. Global variables

function desen_x(){
 let that = this;
 var desen=["h_1","h_2","h_3","h_4","h_5","h_6","h_7","h_8",
 "h_9","h_10","h_11","h_12","h_13","p_1","p_2","p_3","p_4"
 ,"p_5","p_6","p_7","p_8","p_9","p_10","p_11","p_12","p_13"
 ,"t_1","t_2","t_3","t_4","t_5","t_6","t_7","t_8","t_9","t_10"
 ,"t_11","t_12","t_13","x_1","x_2","x_3","x_4","x_5","x_6","x_7"
 ,"x_8","x_9","x_10","x_11","x_12","x_13"];
 //Store all your poker prefix names in an array var Obj = new Object(); //Create a new object var array=[]; //Empty array for(var i=0;i<4;i++){ //Only 4 poker cards are needed in the game demo, so only <4 
   var x=Math.round(Math.random()*52);//Random number rounded*52
   Obj[i]=x; //Store in global variable, otherwise only one value can be stored at a time}
 console.log(Obj);//Print the object to see if there are 4 objects window.array=[desen[Obj[0]],desen[Obj[1]],desen[Obj[2]],desen[Obj[3]]];
 // Bring the stored array into the poker global }
function send_poker(){ //This method is the card dealing event console.log(window.array);
 //Test whether your global variables are normal//and bring the passed global variables into temp[]
 var temp=[window.array[0],window.array[1],window.array[2],window.array[3]];
 var ti=0;
 var iamges="../poker/"+temp+".png"; //This is the default path of the image + your desen
 var creator = document.getElementById("d_back"); //Get the DOM parent element of the operation var po_1 = document.createElement("div"); //Virtual generation of div
 var num = 0; // Initialize variables //po_1.src="../h_1.png";
 //img_1.scr="../images/poker/h_1.png";
 
 for(var i=0;i<temp.length;i++){//loop temp
  var that=this;
  var img_1 = document.createElement("img");
  img_1.src+="./images/poker/"+temp[i]+".png"; //Assign a variable path to the created img console.log("when it is equal to 0");
  var ten=10;
  img_1.className="poker_float";//Assign a class to it, which is the default initial dealing position creator.appendChild(img_1);//Generate object//"../images/poker/"+temp.i+".png";
  
 }

 
  move_poker(); //This method is a self-encapsulated animation}

Animation Events

function move_poker(){ //Move poker var node = document.getElementById("d_back").childNodes; //Get all child nodes under the parent element console.log(node); //Print out how many var n5=node[9]; //Start the operation with the img object class to be operated as 9 var n6=node[10];
 var n7=node[11];
 var n8=node[12];
 var popo = anime({//animation can be viewed at the end targets: n5, //operated object translateX:-150, //horizontal position to move to translateY: -250, //vertical position to move to easing: 'easeInOutQuad', //easing, no change to CSS mechanism duration:100, //completion time });
  var popo1 = anime({
  targets: n6,
  translateX:-100,
  translateY: -250,
  easing: 'easeInOutQuad',
  duration:200,
  });
  var popo2 = anime({
  targets: n7,
  translateX:-50,
  translateY: -250,
  easing: 'easeInOutQuad',
  duration:300,
  });
  var popo3 = anime({
  targets: n8,
  translateX:0,
  translateY: -250,
  easing: 'easeInOutQuad',
  duration:400,
  });
}
function gui(){ //GUI resets all nodes to facilitate the next card deal var node = document.getElementById("d_back").childNodes;
 var n5=node[9];
 var n6=node[10];
 var n7=node[11];
 var n8=node[12];
 var popo4 = anime({
  targets: [n5,n6,n7,n8],
  translateX:0,
  translateY: 0,
 })
 node.removeChild(popo4);
}

animation package

function setAnimationsProgress(insTime) { //When this method has multiple doms, it executes XOR asynchronous thread mode var i = 0;
 var animations = instance.animations;
 var animationsLength = animations.length; 
 while (i < animationsLength) { 
  var anim = animations[i];
  var animatable = anim.animatable;
  var tweens = anim.tweens;
  var tweenLength = tweens.length - 1;
  var tween = tweens[tweenLength];
  if (tweenLength) { tween = filterArray(tweens, function (t) { return (insTime < t.end); })[0] || tween; } 
  var elapsed = minMax(insTime - tween.start - tween.delay, 0, tween.duration) / tween.duration;
  var eased = isNaN(elapsed) ? 1 : tween.easing(elapsed);
  var strings = tween.to.strings;
  var round = tween.round;
  var numbers = [];
  var toNumbersLength = tween.to.numbers.length;
  var progress = (void 0);
  for (var n = 0; n < toNumbersLength; n++) {
  var value = (void 0);
  var toNumber = tween.to.numbers[n];
  var fromNumber = tween.from.numbers[n] || 0;
  if (!tween.isPath) {
   value = fromNumber + (eased * (toNumber - fromNumber));
  } else {
   value = getPathProgress(tween.value, eased * toNumber);
  }
  if (round) {
   if (!(tween.isColor && n > 2)) {
   value = Math.round(value * round) / round;
   }
  }
  numbers.push(value);
  }
  var stringsLength = strings.length;
  if (!stringsLength) {
  progress = numbers[0];
  } else {
  progress = strings[0];
  for (var s = 0; s < stringsLength; s++) {
   var a = strings[s];
   var b = strings[s + 1];
   var n$1 = numbers[s];
   if (!isNaN(n$1)) {
   if (!b) {
    progress += n$1 + ' ';
   } else {
    progress += n$1 + b;
   }
   }
  }
  }
  setProgressValue[anim.type](animatable.target, anim.property, progress, animatable.transforms);
  anim.currentValue = progress;
  i++;
 }
}

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+canvas realizes card game

<<:  Detailed explanation of efficient MySQL paging

>>:  Summary of several postures that must be mastered in Linux compilation optimization

Recommend

How to prevent users from copying web page content using pure CSS

Preface When I was typing my own personal blog, I...

Example of how to upload a Docker image to a private repository

The image can be easily pushed directly to the Do...

Ubuntu16.04 installation mysql5.7.22 graphic tutorial

VMware12.0+Ubuntu16.04+MySQL5.7.22 installation t...

MySQL 5.7.17 compressed package installation-free configuration process diagram

There are two versions of MySQL database manageme...

5 VueUse libraries that can speed up development (summary)

Table of contents What utilities does VueUse have...

Example of implementing a virtual list in WeChat Mini Program

Table of contents Preface analyze Initial Renderi...

Method example of safely getting deep objects of Object in Js

Table of contents Preface text parameter example ...

MySQL 8.0.12 Quick Installation Tutorial

The installation of MySQL 8.0.12 took two days an...

How to extend Vue Router links in Vue 3

Preface The <router-link> tag is a great to...

JavaScript implements long image scrolling effect

This article shares the specific code of JavaScri...

Several commonly used methods for centering CSS boxes (summary)

The first one: Using the CSS position property &l...

How to create LVM for XFS file system in Ubuntu

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

How to understand the difference between computed and watch in Vue

Table of contents Overview computed watch monitor...

MySQL database operation and maintenance data recovery method

The previous three articles introduced common bac...

HTML structured implementation method

DIV+css structure Are you learning CSS layout? Sti...