当前位置:网站首页>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%);
}边栏推荐
- [mathematical logic] predicate logic (toe normal form | toe normal form conversion method | basic equivalence of predicate logic | name changing rules | predicate logic reasoning law)
- Feature_selection
- JS实现图片懒加载
- [graduation season · aggressive technology Er] Confessions of workers
- [set theory] set concept and relationship (set family | set family examples | multiple sets)
- [brush questions] find the number pair distance with the smallest K
- Mila, University of Ottawa | molecular geometry pre training with Se (3) invariant denoising distance matching
- 使用BENCHMARKSQL工具对KingbaseES执行测试时报错funcs sh file not found
- Interface in TS
- mysql字段userid逗号分开保存按userid查询
猜你喜欢

因果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

国产PC系统完成闭环,替代美国软硬件体系的时刻已经到来

使用BENCHMARKSQL工具对kingbaseES执行灌数据提示无法找到JDBC driver

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

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

会员积分商城系统的功能介绍

使用BENCHMARKSQL工具对KingbaseES预热数据时执行:select sys_prewarm(‘NDX_OORDER_2 ‘)报错

Preliminary cognition of C language pointer

Feature_selection
随机推荐
Basic types of data in TS
【毕业季·进击的技术er】职场人的自白
国产PC系统完成闭环,替代美国软硬件体系的时刻已经到来
JS realizes lazy loading of pictures
DAPP for getting started with eth
Bisher - based on SSM pet adoption center
Solve BP Chinese garbled code
深潜Kotlin协程(二十):构建 Flow
[NLP]—sparse neural network最新工作简述
The time has come for the domestic PC system to complete the closed loop and replace the American software and hardware system
【刷题篇】多数元素(超级水王问题)
Two points -leetcode-540 A single element in an ordered array
类的基础语法
What are the Bluetooth headsets with good sound quality in 2022? Inventory of four high-quality Bluetooth headsets
[graduation season · aggressive technology Er] Confessions of workers
eth入门之DAPP
Mila、渥太华大学 | 用SE(3)不变去噪距离匹配进行分子几何预训练
MySQL create table
Introduction to eth
Xrandr modifier la résolution et le taux de rafraîchissement