WeChat applet realizes the effect of shaking the sieve

WeChat applet realizes the effect of shaking the sieve

This article shares the specific code of the WeChat applet to achieve the shaking sieve effect for your reference. The specific content is as follows

1. Effect diagram:

2.HTML code:

<!--pages/game/game.wxml-->

<view class="text">The number of sieve points is: {{total}}</view>
<view class="point1">
  <image src="{{top}}">
  </image>
</view>
<view class="point2">
  <image src="{{left}}"></image>
  <image src="{{right}}">
  </image>
</view>
<button class='{{btn}}' bindtap='click'>{{texts}}</button>

3.js code:

data: {
    top: "../images/images/1-point.png",
    total: '',
    left: "../images/images/2-point.png",
    right: "../images/images/3-point.png",
    btn: '.btnStart',
    texts:'Shake it',
    flag: true,
    img:[
      "../images/images/1-point.png",
      "../images/images/2-point.png",
      "../images/images/3-point.png",
      "../images/images/4-point.png",
      "../images/images/5-point.png",
      "../images/images/6-point.png"

    ]

  },

  /**
   * Life cycle function--listen for page loading*/
 click:function(){
   var self = this;
   if(this.data.flag){
    
     self.timer = setInterval(function(){
       var one = Math.floor(Math.random() * 6);
       var two = Math.floor(Math.random() * 6);
       var three = Math.floor(Math.random() * 6);
        self.setData({          
          top: self.data.img[one],
          left: self.data.img[two],
          right: self.data.img[three],
          total:one+two+three+3,
          
        })
     },200)
     self.setData({
       btn: ".btnEnd",
       texts: 'Stop',
       flag:false,
     })
     
   } else {
     clearInterval(self.timer);

     self.setData({
       btn: ".btnStart",
       texts: 'Shake it',
       flag: true,


     })

   }
   
 },

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:
  • Mini Program to Implement Sieve Lottery

<<:  Tutorial on binary compilation and installation of MySql centos7 under Linux

>>:  MySQL 5.7.23 decompression version installation tutorial with pictures and text

Recommend

How to install MySQL 8.0.17 and configure remote access

1. Preparation before installation Check the data...

Do you know the difference between empty value and null value in mysql

Preface Recently I found that my friend's met...

Detailed tutorial on installing MariaDB on CentOS 8

MariaDB database management system is a branch of...

How to configure the same domain name for the front and back ends of nginx

This article mainly introduces the method of conf...

A brief analysis of how MySQL implements transaction isolation

Table of contents 1. Introduction 2. RC and RR is...

This article will show you what Vite does to the browser's request

Table of contents Working principle: What does th...

HTML insert image example (html add image)

Inserting images into HTML requires HTML tags to ...

How to backup and restore the mysql database if it is too large

Command: mysqlhotcopy This command will lock the ...

Vue implements a small countdown function

Countdown function needs to be implemented in man...

Linux system disk formatting and manually adding swap partition

Windows: Support NTFS, FAT Linux supports file fo...

Detailed explanation of CSS3 animation and new features of HTML5

1. CSS3 animation ☺CSS3 animations are much easie...