当前位置:网站首页>小程序轮播图实现由远及近动画
小程序轮播图实现由远及近动画
2022-08-08 14:48:00 【richest_qi】
搭建资源服务器
- 全局安装serve:
npm install -g serve - 在任何你想的地方新建文件夹:
resources。resources下新建文件夹:images,用于存放静态图片资源。 - 启动服务器:
serve resources。
小程序项目
代码涉及的文件有:
- index.html
- index.wxss
- index.js

index.html
<view class="swiper-container">
<swiper style="height:{
{
swiperH}}" class="swiper" bindchange="handleChange" autoplay circular duration="1500" bindtransition="handleTransition" bindanimationfinish="handleAnimationFinish">
<swiper-item wx:for="{
{imgList}}" wx:key="id" class="swiper-item">
<view class="box">
<image src="{
{item.url}}" bindload="getHeight" style="height:{
{
swiperH}}" class="img {
{index===curIndex?'image-use-animate':'image-unuse-animate'}}"></image>
<view class="box-title {
{index===curIndex?'title-use-animate':'title-unuse-animate'}}">{
{item.title}}</view>
</view>
</swiper-item>
</swiper>
</view>
index.wxss
page{
height: 100%;
width: 100%;
padding: 0 10rpx;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
}
.swiper-container{
width: 100%;
border-radius: 10rpx;
overflow: hidden;
}
.swiper-item .img{
width: 100%;
transform-style: preserve-3d;
transform: translateZ(0);
}
.image-use-animate{
animation: depthOfFocus 3s 1s ease-in-out both;
}
.image-unuse-animate{
animation: none;
}
.box{
width: 100%;
height: 100%;
perspective: 300rpx;
overflow: hidden;
}
.box-title{
position: absolute;
left: 0;
right: 0;
font-size: 36rpx;
text-align: center;
color: #fff;
}
.title-use-animate{
animation: bounceInUp .5s linear .5s both;
}
.title-unuse-animate{
animation: none;
}
@keyframes depthOfFocus{
100% {
transform: translateZ(60rpx);
}
}
@keyframes bounceInUp{
to{
bottom: 10rpx;
}
from{
bottom: -50rpx;
}
}
index.js
const host = "http://localhost:3000"
Page({
data:{
swiperH:0,
imgList:[
{
id:"001",url:host+'/images/1.jpg',title:"公司简介"},
{
id:"002",url:host+'/images/2.jpg',title:"愿景及使命"},
{
id:"003",url:host+'/images/3.jpg',title:"发展历程"},
{
id:"004",url:host+'/images/4.jpg',title:"业务架构"},
{
id:"005",url:host+'/images/5.jpg',title:"管理团队"}
],
curIndex:0
},
getHeight:function(e){
var winWid = wx.getSystemInfoSync().windowWidth;//获取当前屏幕的宽度
var imgh = e.detail.height;//图片高度
var imgw = e.detail.width;
var sH = winWid * imgh / imgw + "px"
this.setData({
swiperH: sH//设置高度
})
},
handleChange(event){
//轮播开始
this.setData({
curIndex:event.detail.current});
},
handleTransition(event){
//轮播过程
// console.log("enter transition",event);
},
handleAnimationFinish(event){
//轮播结束
// console.log("enter animation finish",event);
}
})
相关链接
边栏推荐
- 零基础入门华为云数据库RDS【华为云至简致远】
- 【控制】动力学建模简介 --> 牛顿-欧拉 (Newton-Euler) 法和拉格朗日 (Lagrange) 法
- 星起航跨境—跨境电商进入3.0时代,卖家迎来全新机遇
- 1052. The Angry Bookstore Boss
- logistic regression model - based on R
- Zhaoqi Technology Innovation and Entrepreneurship Event Event Platform, Investment and Financing Matchmaking, Online Live Roadshow
- [Small Coder Study Room] [NOI Online 2020-2 Beginner Group] Finished: Abominable precision will make you burnt
- H5不同屏幕大小显示不同的文字大小图片大小
- 俄驻美大使馆:扎波罗热核电站遭炮击威胁欧洲核安全
- Create a 2D array
猜你喜欢
随机推荐
[Small Coder Study Room] [NOI Online 2020-2 Beginner Group] Finished: Abominable precision will make you burnt
优雅地实时检测和更新 Web 应用
"Small yards artisan study room" friends of friends is not a friend
小白大白读论文-关于EfficientNetV2论文的 疑问 与 总结
window停掉指定端口的进程
JS-BOM-for, if (string to case)
【小码匠自习室】AGC023-A :为啥总是N连发?为啥总遇到大神?
非科班毕业生,五面阿里:四轮技术面+HR一面已拿offer
logistic regression model - based on R
万字长文:常见的软件测试面试题(附答案)
Fast DDS 共享内存测试例修改栈空间大小的方式-如改为30M
Introduction to Recurrent Neural Network (RNN)
初窥门径代码起手,Go lang1.18入门精炼教程,由白丁入鸿儒,首次运行golang程序EP01
JS-BOM-for,if(字符串转大小写)
JS加法器(DOM)
软考 --- 软件工程(6)软项目管理
更改C盘用户目录下的用户名(亲测有效)
有了国产 DevOps 工具 ,还怕数字化转型成本高?
【控制】动力学建模举例 --> 牛顿-欧拉法
Elegantly detect and update web applications in real time









