当前位置:网站首页>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%);
}边栏推荐
- Five elements of user experience
- Idea shortcut keys
- CVPR 2022 | Dalian Institute of technology proposes a self calibration lighting framework for low light level image enhancement of real scenes
- 【刷题篇】多数元素(超级水王问题)
- Mila, University of Ottawa | molecular geometry pre training with Se (3) invariant denoising distance matching
- vulnhub HA: Natraj
- [Blue Bridge Road - bug free code] pcf8591 - code analysis of AD conversion
- Interface in TS
- [brush questions] find the number pair distance with the smallest K
- MySQL timestampdiff interval
猜你喜欢

因果AI,下一代可信AI的产业升级新范式?

CVPR 2022 | Dalian Technology propose un cadre d'éclairage auto - étalonné pour l'amélioration de l'image de faible luminosité de la scène réelle

Pdf editing tool movavi pdfchef 2022 direct download

Which code editor is easy to use? Code editing software recommendation

Solve BP Chinese garbled code
![[pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius](/img/01/c118725f74e39742df021b5dbcc33b.jpg)
[pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius

The time has come for the domestic PC system to complete the closed loop and replace the American software and hardware system

Mila, University of Ottawa | molecular geometry pre training with Se (3) invariant denoising distance matching

中移物联网OneOS与OneNET入选《2021年物联网示范项目名单》

redis 持久化原理
随机推荐
[set theory] ordered pair (ordered pair | ordered triple | ordered n ancestor)
树莓派如何连接WiFi
Introduction to eth
Basic MySQL operations
一名外包仔的2022年中总结
Pdf editing tool movavi pdfchef 2022 direct download
[fairseq] 报错:TypeError: _broadcast_coalesced(): incompatible function arguments
[mathematical logic] predicate logic (judge whether the first-order predicate logic formula is true or false | explain | example | predicate logic formula type | forever true | forever false | satisfi
深潜Kotlin协程(十九):Flow 概述
Dismantle a 100000 yuan BYD "Yuan". Come and see what components are in it.
[home push IMessage] software installation virtual host rental tothebuddy delay
[set theory] set concept and relationship (true subset | empty set | complete set | power set | number of set elements | power set steps)
Basic types of data in TS
2022deepbrainchain biweekly report no. 104 (01.16-02.15)
xrandr修改分辨率与刷新率
"Designer universe" argument: Data Optimization in the design field is finally reflected in cost, safety and health | chinabrand.com org
Mutex and rwmutex in golang
【刷题篇】多数元素(超级水王问题)
使用BENCHMARKSQL工具对kingbaseES执行灌数据提示无法找到JDBC driver
竞品分析撰写