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

Two implementation solutions for vuex data persistence

Table of contents Business requirements: Solution...

MySQL aggregate function sorting

Table of contents MySQL result sorting - Aggregat...

How to use node to implement static file caching

Table of contents cache Cache location classifica...

Idea deployment tomcat service implementation process diagram

First configure the project artifacts Configuring...

Detailed introduction to Mysql date query

Query the current date SELECT CURRENT_DATE(); SEL...

How to configure the Runner container in Docker

1. Create a runner container mk@mk-pc:~/Desktop$ ...

Detailed explanation of the process of building an MQTT server using Docker

1. Pull the image docker pull registry.cn-hangzho...

Detailed explanation of vue simple notepad development

This article example shares the specific code of ...

Vue implements various ideas for detecting sensitive word filtering components

Table of contents Written in front Requirements A...

Solution to the error reported by Mysql systemctl start mysqld

Error message: Job for mysqld.service failed beca...

Implementation of Docker deployment of SQL Server 2019 Always On cluster

Table of contents Docker deployment Always on clu...

Detailed process of changing apt source to Alibaba Cloud source in Ubuntu 18.04

Table of contents Preface: Ubuntu 18.04 changes a...

How to embed flash video format (flv, swf) files in html files

Flash file formats: .FLV and .SWF There are two ex...