当前位置:网站首页>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%);
}边栏推荐
- 一名外包仔的2022年中总结
- Application of I2C protocol of STM32F103 (read and write EEPROM)
- 【刷题篇】 找出第 K 小的数对距离
- 2022deepbrainchain biweekly report no. 104 (01.16-02.15)
- Dismantle a 100000 yuan BYD "Yuan". Come and see what components are in it.
- 国产PC系统完成闭环,替代美国软硬件体系的时刻已经到来
- Redraw and reflow
- How to connect WiFi with raspberry pie
- Social phobia of contemporary young people (III)
- [mathematical logic] predicate logic (toe normal form | toe normal form conversion method | basic equivalence of predicate logic | name changing rules | predicate logic reasoning law)
猜你喜欢

【刷题篇】接雨水(一维)
![[dynamic programming] subsequence problem](/img/d8/020ae959ef53ce097d3a81a0d2d63a.jpg)
[dynamic programming] subsequence problem

vulnhub HA: Natraj
![[Apple Push] IMessage group sending condition document (push certificate) development tool pushnotification](/img/30/c840e28c0ef7c8ce574dcde4363863.jpg)
[Apple Push] IMessage group sending condition document (push certificate) development tool pushnotification

Esp32 series (3): GPIO learning (take simple GPIO input and output, ADC, DAC as examples)

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

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

JS native common knowledge
![[literature reading] sparse in deep learning: practicing and growth for effective information and training in NN](/img/7e/50fa6f65b5a4f0bb60909f57daff56.png)
[literature reading] sparse in deep learning: practicing and growth for effective information and training in NN

Fcpx template: sweet memory electronic photo album photo display animation beautiful memory
随机推荐
RSRS指标择时及大小盘轮动
vim 的实用操作
Feature_selection
How do you use lodash linking function- How do you chain functions using lodash?
Interaction free shell programming
[set theory] inclusion exclusion principle (including examples of exclusion principle)
服务器无法远程连接原因分析
Causal AI, a new paradigm for industrial upgrading of the next generation of credible AI?
How to process the current cell with a custom formula in conditional format- How to address the current cell in conditional format custom formula?
Daily question - ugly number
[mathematical logic] predicate logic (predicate logic basic equivalent | eliminate quantifier equivalent | quantifier negative equivalent | quantifier scope contraction expansion equivalent | quantifi
CVPR 2022 | 大連理工提出自校准照明框架,用於現實場景的微光圖像增强
树莓派如何连接WiFi
vulnhub HA: Natraj
eth入门之简介
Social phobia of contemporary young people (II)
vulnhub HA: Natraj
How to connect WiFi with raspberry pie
[nlp] - brief introduction to the latest work of spark neural network
Database management tool, querious direct download