当前位置:网站首页>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%);
}边栏推荐
- 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
- 竞品分析撰写
- [dynamic programming] subsequence problem
- 2.14 simulation summary
- DAPP for getting started with eth
- [fxcg] market analysis today
- Basic types of data in TS
- [set theory] set concept and relationship (set family | set family examples | multiple sets)
- xrandr修改分辨率与刷新率
- Xrandr modify resolution and refresh rate
猜你喜欢

300+ documents! This article explains the latest progress of multimodal learning based on transformer

Solve BP Chinese garbled code

Which Bluetooth headset is good about 400? Four Bluetooth headsets with strong noise reduction are recommended

Supervised pre training! Another exploration of text generation!

Preliminary cognition of C language pointer

"Final review" 16/32-bit microprocessor (8086) basic register

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

Mila、渥太华大学 | 用SE(3)不变去噪距离匹配进行分子几何预训练
![[fxcg] market analysis today](/img/ac/294368e3496a5b808b38833053ee81.jpg)
[fxcg] market analysis today

Which code editor is easy to use? Code editing software recommendation
随机推荐
[set theory] set concept and relationship (set family | set family examples | multiple sets)
金仓KFS数据双向同步场景部署
[fxcg] inflation differences will still lead to the differentiation of monetary policies in various countries
How to process the current cell with a custom formula in conditional format- How to address the current cell in conditional format custom formula?
When writing a web project, SmartUpload is used for file upload and new string () is used for transcoding, but in the database, there will still be random codes similar to poker
【毕业季·进击的技术er】职场人的自白
跨境电商多商户系统怎么选
Solve BP Chinese garbled code
Introduction of pointer variables in function parameters
vulnhub HA: Natraj
Basic syntax of class
Dismantle a 100000 yuan BYD "Yuan". Come and see what components are in it.
[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
Mila、渥太华大学 | 用SE(3)不变去噪距离匹配进行分子几何预训练
[literature reading] sparse in deep learning: practicing and growth for effective information and training in NN
Js/ts bottom implementation double click event
"Designer universe" argument: Data Optimization in the design field is finally reflected in cost, safety and health | chinabrand.com org
使用BENCHMARKSQL工具对kingbaseES执行灌数据提示无法找到JDBC driver
Drf--- quick start 01
中移物联网OneOS与OneNET入选《2021年物联网示范项目名单》