当前位置:网站首页>Small program animation realizes the running lantern and animation object
Small program animation realizes the running lantern and animation object
2022-07-03 04:18:00 【Hey_ Swang】
The effect of running lantern is a common requirement in development
For example, website notification 、 Winning notice 、 Notice 、 Gift giving notice, etc
The following code , Animated objects using applets Animation, The running lantern effect achieved :
<button bindtap="start"> Start the animation </button>
<view class='marquee_container'>
<image class="gift-img" src="{
{currentLogs.gift.pic}}" mode="widthFix"></image>
<view class="marquee_main">
<view id="marquee_wrap" class='marquee_text' animation="{
{ani}}" bindtransitionend="animationend">
<text>{
{currentLogs.from.name}} Give </text>
<view>LV{
{currentLogs.userLevel}}</view>
<text>{
{currentLogs.to.name}}</text>
<text>{
{currentLogs.gift.name}}</text>
<text>{
{'X' + currentLogs.num}}</text>
<view> Popularity value :{
{currentLogs.charm}}</view>
</view>
</view>
</view>
Page({
data: {
ani: "",
length: 0, // Width of animation content area
currentLogs: {
charm: 10,
from: {
name: " Wu Yanzu ",
},
gift: {
name: " The roses ",
pic: "https://avatar-img.wuhan716.com/voice/gift_rose.png",
},
num: 1,
to: {
name: " peng ",
},
userLevel: 4,
},
},
start() {
wx.nextTick(() => {
this.dynamicLength().then(() => {
setTimeout(() => {
this.startAni();
}, 1000);
});
});
},
// Get content area width
dynamicLength() {
return new Promise((resolve) => {
const that = this;
const query = wx.createSelectorQuery().in(this);
query
.select("#marquee_wrap")
.boundingClientRect((rect) => {
that.setData(
{
length: rect.width,
},
resolve()
);
})
.exec();
});
},
// Start the animation
startAni() {
const { length } = this.data;
const duration = Math.round(length) * 16;
const animation = wx.createAnimation({
duration,
timingFunction: "linear",
delay: 0,
});
animation.translateX(-length).step();
this.setData({
ani: animation.export(),
});
},
// Call... At the end of the animation
animationend() {
const animation = wx.createAnimation({
duration: 0,
timingFunction: "linear",
delay: 0,
});
animation.translateX(375).step();
this.setData({
ani: animation.export(),
});
},
});
.marquee_container {
position: relative;
top: 50rpx;
left: 0;
width: 100%;
height: 57rpx;
padding-left: 120rpx;
}
.marquee_main{
position: relative;
width: 630rpx;
height: 57rpx;
overflow: hidden;
font-size: 28rpx;
background: cyan;
}
.marquee_text {
height: 57rpx;
position: absolute;
white-space: nowrap;
top: 0;
transform: translateX(750rpx);
display: flex;
align-items: center;
}
.gift-img {
width: 120rpx;
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
}边栏推荐
- Taking two column waterfall flow as an example, how should we build an array of each column
- "Final review" 16/32-bit microprocessor (8086) basic register
- Practical operation of vim
- [set theory] set identities (idempotent law | exchange law | combination law | distribution rate | De Morgan law | absorption rate | zero law | identity | exclusion law | contradiction law | complemen
- 解决bp中文乱码
- leetcode:297. Serialization and deserialization of binary tree
- [untitled] 2022 safety production supervisor examination question bank and simulated safety production supervisor examination questions
- Mutex and rwmutex in golang
- What's wrong with SD card data damage? How to recover SD card data damage
- "Designer universe" argument: Data Optimization in the design field is finally reflected in cost, safety and health | chinabrand.com org
猜你喜欢
![[fxcg] market analysis today](/img/ac/294368e3496a5b808b38833053ee81.jpg)
[fxcg] market analysis today

【刷题篇】 找出第 K 小的数对距离

深潜Kotlin协程(十九):Flow 概述

The time has come for the domestic PC system to complete the closed loop and replace the American software and hardware system
![[dynamic programming] subsequence problem](/img/d8/020ae959ef53ce097d3a81a0d2d63a.jpg)
[dynamic programming] subsequence problem

Five elements of user experience

Which Bluetooth headset is cost-effective? Four Bluetooth headsets with high cost performance are recommended

因果AI,下一代可信AI的产业升级新范式?
![[brush questions] connected with rainwater (one dimension)](/img/21/318fcb444b17be887562f4a9c1fac2.png)
[brush questions] connected with rainwater (one dimension)

金仓KFS数据双向同步场景部署
随机推荐
Xrandr modify resolution and refresh rate
[NLP]—sparse neural network最新工作简述
[fairseq] 报错:TypeError: _broadcast_coalesced(): incompatible function arguments
Mila、渥太华大学 | 用SE(3)不变去噪距离匹配进行分子几何预训练
Xrandr modifier la résolution et le taux de rafraîchissement
220214c language learning diary
Analysis of the reason why the server cannot connect remotely
leetcode:297. Serialization and deserialization of binary tree
xrandr修改分辨率與刷新率
[graduation season · aggressive technology Er] Confessions of workers
深潜Kotlin协程(十九):Flow 概述
Idea shortcut keys
The time has come for the domestic PC system to complete the closed loop and replace the American software and hardware system
MPLS setup experiment
Basic MySQL operations
有监督预训练!文本生成又一探索!
【刷题篇】多数元素(超级水王问题)
[literature reading] sparse in deep learning: practicing and growth for effective information and training in NN
Appium automated testing framework
Reflection and planning of a sophomore majoring in electronic information engineering