当前位置:网站首页>Wechat applet to realize stacked rotation
Wechat applet to realize stacked rotation
2022-06-24 18:13:00 【Susu is little Susu】
1. Realization effect

2. Realization principle
1.css Of var() function
var() Function to insert the value of a custom attribute , Instead of any part of the value of another property .
grammar :
var(custom-property-name, value)

eg:
:root {
--main-bg-color: coral;
--main-txt-color: blue;
--main-padding: 15px;
}
#div1 {
background-color: var(--main-bg-color);
color: var(--main-txt-color);
padding: var(--main-padding);
}
#div2 {
background-color: var(--main-bg-color);
color: var(--main-txt-color);
padding: var(--main-padding);
}
2. Use inline styles , Distinguish between different styles
Get the value of each item
style="--index:{
{item.zIndex}};--left:{
{item.mLeft}}"
Set different zoom sizes , Level , A relatively central position
transform: scale(calc(0.5 + var(--index) / 10));
margin-left: calc(var(--left) * 100rpx - 150rpx);
z-index: var(--index);
3. Initialization data , Set the corresponding... For the data z-index and mleft
4. Combined with Events :bindtouchmove,bindtouchstart,bindtouchend
Applet events :
- Events are a way of communicating from the view layer to the logical layer .
- Events can feed back the user's behavior to the logic layer for processing .
- Events can be bound to components , When the trigger event is reached , It will execute the corresponding event handler function in the logic layer .
- Event objects can carry extra information , Such as id, dataset,touches. How events are used
Events are divided into bubble events and non bubble events :
Bubbling event : When an event on a component is triggered , This event passes... To the parent node .
Non bubbling Events : When an event on a component is triggered , The event does not pass... To the parent node .
Bubble event list :
notes : Other component custom events except the above table are non bubbling events without special declaration , Such as form Of submit event ,input Of input event ,scroll-view Of scroll event
How to bind and prevent event bubbling ?
except bind Outside , It can also be used. catch To bind events . And bind Different , catch Will prevent the event from bubbling up .
3. Implementation code
<view class="swiper-box" bindtouchmove="tauchMove" bindtouchstart="tauchStart" bindtouchend="tauchEnd">
<view class="item-box {
{item.zIndex==1?'none':''}}" wx:for="{
{swiperList}}" wx:key="index" style="--index:{
{item.zIndex}};--left:{
{item.mLeft}}">
<view class="swiper-item">
<image src="{
{item.url}}" mode="aspectFill" wx:if="{
{item.type=='image'}}"></image>
<video src="{
{item.url}}" autoplay loop muted show-play-btn="{
{false}}" controls="{
{false}}" objectFit="cover" wx:if="{
{item.type=='video'}}"></video>
</view>
</view>
</view>
/* pages/another/cust-swiper/index.wxss */
page {
background-color: #fff;
}
.swiper-item image,
.swiper-item video {
width: 100%;
display: block;
height: 100%;
margin: 0;
pointer-events: none;
}
image {
max-width: 100%;
display: inline-block;
position: relative;
z-index: 0;
}
.swiper-box {
height: 420rpx;
position: relative;
max-width: 750rpx;
overflow: hidden;
box-sizing: border-box;
margin-top: 90rpx;
}
.swiper-box .item-box {
position: absolute;
width: 300rpx;
height: 380rpx;
top: 0;
bottom: 0;
left: 50%;
margin: auto;
transition: all 0.2s ease-in 0s;
opacity: 1;
box-shadow: 0px 13rpx 12rpx rgba(0, 0, 0, .5);
border-radius: 15rpx;
overflow: hidden;
}
.swiper-box .item-box.none {
opacity: 0;
}
.swiper-box .item-box .swiper-item {
width: 100%;
height: 100%;
border-radius: 6rpx;
overflow: hidden;
}
.swiper-box .item-box {
transform: scale(calc(0.5 + var(--index) / 10));
margin-left: calc(var(--left) * 100rpx - 150rpx);
z-index: var(--index);
}
// pages/another/cust-swiper/index.js
Page({
data: {
swiperList: [
{
type: 'video',
url: 'https://static.51dh.com.cn/dbp/12/98/4494bd8a6e0fcd4a992f25a42bea28f8d1fb.mp4'
}, {
type: 'image',
url: 'https://i.postimg.cc/mgsKJGLw/susu1.jpg'
}, {
type: 'image',
url: 'https://i.postimg.cc/qRRLS16Q/susu0.jpg',
}, {
type: 'image',
url: 'https://i.postimg.cc/pXDp6RXq/susu3.jpg'
}, {
type: 'image',
url: 'https://i.postimg.cc/XJmpTvCD/susu2.jpg'
}, {
type: 'image',
url: 'https://i.postimg.cc/76br1jzJ/susu1.jpg'
}, {
type: 'image',
url: 'https://i.postimg.cc/pXDp6RXq/susu3.jpg'
},
{
type: 'image',
url: 'https://i.postimg.cc/XJmpTvCD/susu2.jpg'
},
],
},
onLoad: function (options) {
this.tauchSwiper('swiperList');
},
onShow: function () {
},
// initialization tauchSwiper
tauchSwiper(name) {
let list = this.data[name];
for (let i = 0; i < list.length; i++) {
// Math.abs(x) Function returns the specified number “x“ The absolute value of
list[i].zIndex = parseInt(list.length / 2) + 1 - Math.abs(i - parseInt(list.length / 2))
list[i].mLeft = i - parseInt(list.length / 2)
}
this.setData({
swiperList: list
})
},
// tauchSwiper Touch start
tauchStart(e) {
this.setData({
tauchStart: e.touches[0].pageX
})
},
// tauchSwiper Calculation direction
tauchMove(e) {
this.setData({
direction: e.touches[0].pageX - this.data.tauchStart > 0 ? 'right' : 'left'
})
},
// tauchSwiper Calculate scrolling
tauchEnd(e) {
let direction = this.data.direction;
let list = this.data.swiperList;
if (direction == 'right') {
let mLeft = list[0].mLeft;
let zIndex = list[0].zIndex;
for (let i = 1; i < list.length; i++) {
list[i - 1].mLeft = list[i].mLeft
list[i - 1].zIndex = list[i].zIndex
}
list[list.length - 1].mLeft = mLeft;
list[list.length - 1].zIndex = zIndex;
this.setData({
swiperList: list
})
} else {
let mLeft = list[list.length - 1].mLeft;
let zIndex = list[list.length - 1].zIndex;
for (let i = list.length - 1; i > 0; i--) {
list[i].mLeft = list[i - 1].mLeft
list[i].zIndex = list[i - 1].zIndex
}
list[0].mLeft = mLeft;
list[0].zIndex = zIndex;
this.setData({
swiperList: list
})
}
}
})
4. More applets demo, Focus on Su Su's code cloud !, For more information , Follow the wechat official account of Susu bug
边栏推荐
- Common MySQL commands of installation free version
- -Bash: wget: command not found
- Cloud service selection of enterprises: comparative analysis of SaaS, PAAS and IAAs
- 13 ways to reduce the cost of cloud computing
- Erc-721 Standard Specification
- 布隆过滤器综述文章论文阅读:Optimizing Bloom Filter: Challenges, Solutions, and Comparisons
- [quick news] the jeecgboot low code platform was successfully selected into the 2021 scientific innovation China · open source innovation list
- Constantly changing the emergency dialing of harmonyos ETS during the new year
- Mysql database performance testing tool recommendation
- Bigdecimalavoiddoubleconstructorrule: do not directly use the double variable as a parameter to construct BigDecimal
猜你喜欢

Project Management Guide: tips, strategies and specific practices

13 ways to reduce the cost of cloud computing

Recommend 14 commonly used test development tools
![[NLP] 3 papers on how Stanford team builds a better chat AI](/img/f1/1c2ff31a728152395618800600df45.jpg)
[NLP] 3 papers on how Stanford team builds a better chat AI
[North Asia data recovery]_ mdb_ catalog. Mongodb database data recovery case in case of WT file corruption

Eight recommended microservice testing tools

How do yaml files and zmail collide with the spark of the framework, and how can code and data be separated gracefully?

Skills of writing test cases efficiently

How can an enterprise successfully complete cloud migration?

He "painted" what a smart city should look like with his oars
随机推荐
Easynvr fails to use onvif to detect the device. What is the reason why "no data" is displayed?
He "painted" what a smart city should look like with his oars
Three years of bug free, tips for improving code quality
Design topic: MATLAB UAV flight operation
Quickly build MySQL million level test data
Number of occurrences of numbers in the array (medium difficulty)
Industrial security experts talk about DDoS countermeasures from the perspective of attack and defense
EasyGBS视频平台TCP主动模式拉流异常情况修复
A solution to the problem that the separator of WordPress title - is escaped as -
Gateway solves cross domain access
Continue to help enterprises' digital transformation -tce has obtained the certification of the first batch of digital trusted service platforms in China
Litamin: SLAM Based on geometric approximation of normal distribution
How does the video platform import the old database into the new database?
Paper sharing | self supervised learning paper jointly released by Yann Lecun and read by engineers
On software requirement analysis
Solutions for RTSP video streaming played by several browsers
Etching process flow for PCB fabrication
Bigdecimalavoiddoubleconstructorrule: do not directly use the double variable as a parameter to construct BigDecimal
Do you charge for PDF merging software? Programmers make one by themselves
腾讯云TCS:面向应用的一站式PaaS 平台