当前位置: 首页 > news >正文

小程序使用this.animate实现3维动画切换

小程序使用this.animate实现3维动画切换

这里以三张图片为例
话不多说,直接上代码

wxml

<view class="container"><view class="carousel" id="carousel_id"><view class="box" wx:for="{{items}}" wx:for-item="item" wx:for-index="index" wx:key="index" style="display: flex;flex-direction: column;transform: rotateY({{index * -120}}deg) translateZ({{translateZ}});"><image class="DoorLock" src="{{item.pic}}" /></view></view>
</view><button type="primary" bindtap="play" style="margin-top: 200rpx;">切换</button>

js


Page({data: {translateZ: '0px',rotateY: 0,items: [{ "name": "酒杏鲍菇", "pic": "https://api.jisuapi.com/recipe/upload/20160719/120829_70383.jpg" },{ "name": "醋黄瓜丝", "pic": "https://api.jisuapi.com/recipe/upload/20160719/120712_61817.jpg" },{ "name": "式柠檬蒸鲈鱼", "pic": "https://api.jisuapi.com/recipe/upload/20160719/115500_14721.jpg" },]},onLoad(options) {const that = this;wx.getSystemInfo({success: (res) => {that.setData({translateZ: (res.windowWidth / 2 - 20) + 'px'});}});console.log('translateZ的值为:' + this.data.translateZ)},play() {let that = thisthis.animate('#carousel_id', [{ ease: 'ease', rotateY: this.data.rotateY },{ ease: 'ease', rotateY: this.data.rotateY+120 }], 500, function () {let rotateY = that.data.rotateY + 120rotateY = rotateY == 360 ? 0 : rotateYthat.setData({rotateY: rotateY})console.log('当前rotateY值为:' + that.data.rotateY)});},
});

wxss

.container {margin: 20rpx 300rpx;width: 70px;height: 40px;position: relative;perspective: 1000px;-webkit-perspective: 1500px;
}.carousel {width: 100%;height: 100%;position: absolute;transform-style: preserve-3d;-webkit-transform-style: preserve-3d;/* animation: rotation 10s infinite linear;-webkit-animation: rotation 10s infinite linear; */
}.carousel:hover {animation-play-state: paused;-webkit-animation-play-state: paused;
}.carousel view {display: block;position: absolute;width: 70px;height: 70px;/* left: 10px; */top: 10px;background: #2262E6;overflow: hidden;border: solid 2px #07C160;
}.box image {filter: grayscale(0);cursor: pointer;transition: all 0.3s ease 0s;width: 100%;height: 100%;
}.box image:hover {filter: grayscale(0);-webkit-filter: grayscale(0);transform: scale(1, 1);-webkit-transform: scale(1, 1);
}@keyframes rotation {from {transform: rotateY(0deg);}to {transform: rotateY(360deg);}
}.DoorLock {position: fixed;opacity: 0.9;height: 70px;width: 70px;/* margin-left: 80rpx; */margin-top: -40px;justify-content: center;/* background-color: greenyellow; */
}

说明

1.点击切换实现3维切换
2.每次点击旋转120度,也就是一圈的三分之一,并且每次会继承上次旋转的角度,不然再次点击时回复原位置
3.rotateY表示每个图片之间的位置角度,这里将三张图片按idnex均匀分布
http://www.lryc.cn/news/419708.html

相关文章:

  • 【区块链+社会公益】第一反应互助急救链 | FISCO BCOS应用案例
  • leetcode 136. 只出现一次的数字
  • 可扩展架构设计:策略与最佳实践
  • 一图胜千言|图解Pandas常用操作!
  • ue5正确导入资源 content(内容),content只能有一个
  • HTTP协议基础知识【后端 4】
  • 2024/8/10 英语每日一段
  • 深入探索 Wireshark——网络封包分析的利器
  • VS2022使用.Net Framework4.0方法
  • 创建一个简单的贪吃蛇游戏:HTML、CSS和JavaScript教程
  • 全面讲解电子齿轮比与脉冲数计算
  • 音频进阶学习一——模拟信号和数字信号
  • SpringBoot企业人事管理系统-附源码与配套论文
  • 用window计算器实现定点数的十进制和二进制之间相互转换
  • 搬砖人2024年的智能工作伙伴 —— 4款思维导图软件种草集!
  • 【Python第三方库】Requests全面解析
  • 基于CNN的医学X-Ray图像分类全程解析
  • C++初学者指南-5.标准库(第二部分)--排序序列操作
  • matplotlib库学习之绘图透明度设置(精炼准确)
  • select多路复用(tcp通信)
  • STM32IIC与SPI详解
  • K8s第三节:k8s1.23.1升级为k8s1.30.0
  • .gitignore不生效的解决方案
  • 脱胎于 S 语言的R语言,Ross Ihaka 和 Robert Gentleman 和社区的力量让 R 在学术界与研究机构放光彩
  • JavaEE 第6节 内存可见性问题以及解决方法
  • es基本操作
  • 开源 AI 智能名片 S2B2C 商城小程序赋能下的社区团购商业模式研究
  • AutoSar AP软件规范中CM介绍及功能概要
  • 【图形学】TA之路-向量
  • [flink]部署模式