当前位置:网站首页>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%);
}
边栏推荐
- Mutex and rwmutex in golang
- Practical operation of vim
- [NLP]—sparse neural network最新工作简述
- Busycal latest Chinese version
- What is the correct way to compare ntext columns with constant values- What's the right way to compare an NTEXT column with a constant value?
- Introduction of pointer variables in function parameters
- Preliminary cognition of C language pointer
- [set theory] set operation (Union | intersection | disjoint | relative complement | symmetric difference | absolute complement | generalized union | generalized intersection | set operation priority)
- 解决bp中文乱码
- Causal AI, a new paradigm for industrial upgrading of the next generation of credible AI?
猜你喜欢
540. Single element in ordered array
【刷题篇】接雨水(一维)
JMeter starts from zero (III) -- simple use of regular expressions
What are the Bluetooth headsets with good sound quality in 2022? Inventory of four high-quality Bluetooth headsets
Pdf editing tool movavi pdfchef 2022 direct download
CVPR 2022 | Dalian Institute of technology proposes a self calibration lighting framework for low light level image enhancement of real scenes
Interaction free shell programming
Nat. Comm. | use tensor cell2cell to deconvolute cell communication with environmental awareness
[graduation season · aggressive technology Er] Confessions of workers
MPLS setup experiment
随机推荐
[dynamic programming] subsequence problem
[software testing-6] & Test Management
The longest subarray length with a positive product of 1567 recorded by leecode
Practical operation of vim
Preliminary cognition of C language pointer
Redis persistence principle
xrandr修改分辨率與刷新率
跨境电商多商户系统怎么选
金仓数据库KingbaseES 插件kdb_date_function
服务器无法远程连接原因分析
Design and implementation of kubelet garbage collection mechanism to protect nodes from being preempted by containers image GC high threshold
PostgreSQL database high availability Patroni source code learning - etcd class
[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
Bisher - based on SSM pet adoption center
[brush questions] find the number pair distance with the smallest K
2022-07-02: what is the output of the following go language code? A: Compilation error; B:Panic; C:NaN。 package main import “fmt“ func main() { var a =
国产PC系统完成闭环,替代美国软硬件体系的时刻已经到来
Analysis of the reason why the server cannot connect remotely
Causal AI, a new paradigm for industrial upgrading of the next generation of credible AI?
【刷题篇】接雨水(一维)