Home > WeChat Applet > Mini Program Development > Implement effects similar to the Tmall lottery wheel and marquee in the mini program

Implement effects similar to the Tmall lottery wheel and marquee in the mini program

高洛峰
Release: 2017-02-28 10:45:38
Original
3577 people have browsed it

When we do e-commerce activities, we often use marquees to attract attention, and use large turntables to achieve the lottery effect.
How can we achieve this effect in WeChat applet development? Please see the explanation below for details.


Functions to be implemented
1. Implement a large carousel similar to Tmall supermarket lottery
2. Then implement the marquee effect
3. Click START to start the lottery and the lottery is completed There will be a pop-up window later


Look at the renderings first

Implement effects similar to the Tmall lottery wheel and marquee in the mini program

Implement effects similar to the Tmall lottery wheel and marquee in the mini program

##Say briefly


1. The flashing ball in the outer circle is a style controlled by js. The style changes every 500ms. It is simple and crude; 2. The lottery item is also a js-controlled background, but how to make it stop gracefully is a problem. There is a timingFunction in the animation. You can set the speed. It is not that simple if you use js yourself. I use setInterval() here, and the time changes linearly. Changing the slope first to a smaller function and then to a larger function should have a better effect.

The following is the page WXML code:

<!--index.wxml--> 
<view class="container-out">  
  <view  
  class="circle" wx:for="{{circleList}}"  
  style="top:{{item.topCircle}}rpx;left:{{item.leftCircle}}rpx;background-color: {{(index%2==0)?colorCircleFirst:colorCircleSecond}};"></view>  
  <view class="container-in">  
    <view class="content-out" wx:for="{{awardList}}" style="top:{{item.topAward}}rpx;left:{{item.leftAward}}rpx;background-color: {{(index==indexSelect)?colorAwardSelect:colorAwardDefault}};">  
      <image class="award-image" src="{{item.imageAward}}"></image>  
    </view>  
    <view class="start-btn" bindtap="startGame" style=" background-color:{{isRunning?&#39;#e7930a&#39;:&#39;#ffe400&#39;}}">START</view>  
  </view>  
</view>
Copy after login

The following is the WXSS code of the page:

/**index.wxss**/ 
   
.container-out {  
  height: 600rpx;  
  width: 650rpx;  
  background-color: #b136b9;  
  margin: 100rpx auto;  
  border-radius: 40rpx;  
  box-shadow: 0 10px 0 #871a8e;  
  position: relative;  
}  
   
.container-in {  
  width: 580rpx;  
  height: 530rpx;  
  background-color: #871a8e;  
  border-radius: 40rpx;  
  position: absolute;  
  left: 0;  
  right: 0;  
  top: 0;  
  bottom: 0;  
  margin: auto;  
}  
   
/**小圆球  
box-shadow: inset 3px 3px 3px #fff2af;*/ 
   
.circle {  
  position: absolute;  
  display: block;  
  border-radius: 50%;  
  height: 20rpx;  
  width: 20rpx;  
}  
   
.content-out {  
  position: absolute;  
  height: 150rpx;  
  width: 166.6666rpx;  
  background-color: #f5f0fc;  
  border-radius: 15rpx;  
  box-shadow: 0 5px 0 #d87fde;  
}  
   
/**居中 加粗*/ 
   
.start-btn {  
  position: absolute;  
  margin: auto;  
  top: 0;  
  left: 0;  
  bottom: 0;  
  right: 0;  
  border-radius: 15rpx;  
  height: 150rpx;  
  width: 166.6666rpx;  
  background-color: #ffe400;  
  box-shadow: 0 5px 0 #e7930a;  
  color: #f6251e;  
  text-align: center;  
  font-size: 55rpx;  
  font-weight: bolder;  
  line-height: 150rpx;  
}  
   
.award-image {  
  position: absolute;  
  margin: auto;  
  top: 0;  
  left: 0;  
  bottom: 0;  
  right: 0;  
  height: 140rpx;  
  width: 130rpx;  
}
Copy after login

The following is the JS code of the page:

//index.js  
//获取应用实例  
var app = getApp()  
Page({  
  data: {  
    circleList: [],//圆点数组  
    awardList: [],//奖品数组  
    colorCircleFirst: &#39;#FFDF2F&#39;,//圆点颜色1  
    colorCircleSecond: &#39;#FE4D32&#39;,//圆点颜色2  
    colorAwardDefault: &#39;#F5F0FC&#39;,//奖品默认颜色  
    colorAwardSelect: &#39;#ffe400&#39;,//奖品选中颜色  
    indexSelect: 0,//被选中的奖品index  
    isRunning: false,//是否正在抽奖  
    imageAward: [  
      &#39;../../images/1.jpg&#39;,  
      &#39;../../images/2.jpg&#39;,  
      &#39;../../images/3.jpg&#39;,  
      &#39;../../images/4.jpg&#39;,  
      &#39;../../images/5.jpg&#39;,  
      &#39;../../images/6.jpg&#39;,  
      &#39;../../images/7.jpg&#39;,  
      &#39;../../images/8.jpg&#39;,  
    ],//奖品图片数组  
  },  
   
  onLoad: function () {
Copy after login


More small The program implements effects similar to the big turntable and marquee of Tmall lottery. For related articles, please pay attention to the PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template