首页 > 其他分享 >uni-app:使用uni-transition动画(hbuilderx 3.6.18)

uni-app:使用uni-transition动画(hbuilderx 3.6.18)

时间:2023-02-21 18:55:53浏览次数:52  
标签:动画 ease console 18 app ani duration uni refs

一,官方文档地址:

https://uniapp.dcloud.net.cn/component/uniui/uni-transition.html

二,代码:

<template>
    <view>
        <view class="animation-element-wrapper">
            <uni-transition :duration="1500" ref="ani" custom-class="transition" :mode-class="modeClass" :styles="styles"
                :show="show"><text class="text">示例元素</text></uni-transition>
        </view>
        
        <scroll-view class="animation-buttons" scroll-y="true">
            <view style="display: flex;flex-direction: row;">
                <button class="animation-button" @tap="goFadeOut">淡出</button>
                <button class="animation-button" @tap="goFadeIn">淡入</button>
            </view>
            <view style="display: flex;flex-direction: row;">
               <button class="animation-button" @tap="fromTopToBottom">由上至下</button>
               <button class="animation-button" @tap="fromBottomToTop">由下至上</button>
            </view>
            <view style="display: flex;flex-direction: row;">
               <button class="animation-button" @tap="fromRightToLeft">由右至左</button>
               <button class="animation-button" @tap="fromLeftToRight">由左至右</button>
            </view>
            <view style="display: flex;flex-direction: row;">
               <button class="animation-button" @tap="magnify">放大</button>
               <button class="animation-button" @tap="reduce">缩小</button>
            </view>
            <view style="display: flex;flex-direction: row;">
               <button class="animation-button" @tap="rotateLeft">向左旋转</button>
               <button class="animation-button" @tap="rotateRight">向右旋转</button>
            </view>
        </scroll-view>
        
    </view>
</template>

<script>
    export default {
        data() {
            return {
                show: true,
                modeClass: 'fade',
                styles: {},
            }
        },
        onl oad() {
            // #ifdef APP-NVUE
            this.styles = {
                justifyContent: 'center',
                alignItems: 'center',
                width: '100px',
                height: '100px',
                borderRadius: '5px',
                textAlign: 'center',
                backgroundColor: '#4cd964',
                boxShadow: '0 0 5px 1px rgba(0,0,0,0.2)',
            }
            // #endif
        },
        methods: {
            goFadeOut:function () {
               this.$refs.ani.step({
                   opacity: '0',
                   //rotate: '0'
               },{
                timingFunction: 'ease-in',
                duration: 1200
               });
               // 开始执行动画
               this.$refs.ani.run(()=>{
                    console.log('动画支持完毕')
               });
            },
            goFadeIn:function () {
               this.$refs.ani.step({
                   opacity: '1',
                   //rotate: '0'
               },{
                timingFunction: 'ease-in',
                duration: 1200
               });
               // 开始执行动画
               this.$refs.ani.run(()=>{
                   console.log('动画支持完毕')
               });
                
            },
            fromTopToBottom:function(){
               this.$refs.ani.step({
                   translateY: '100px',
                   //rotate: '0'
               },{
                timingFunction: 'ease-in',
                duration: 1200
               });
               // 开始执行动画
               this.$refs.ani.run(()=>{
                    console.log('动画支持完毕')
               });
            },
            fromBottomToTop:function(){
               this.$refs.ani.step({
                   translateY: '-100px',
               },{
                timingFunction: 'ease-in',
                duration: 1200
               });
               // 开始执行动画
               this.$refs.ani.run(()=>{
                    console.log('动画支持完毕')
               });
            },
            fromRightToLeft:function(){
               this.$refs.ani.step({
                   translateX: '-100px',
               },{
                timingFunction: 'ease-in',
                duration: 1200
               });
               // 开始执行动画
               this.$refs.ani.run(()=>{
                    console.log('动画支持完毕')
               });
            },
            
            fromLeftToRight:function(){
                           this.$refs.ani.step({
                               translateX: '100px',
                           },{
                               timingFunction: 'ease-in',
                               duration: 1200
                           });
                           // 开始执行动画
                           this.$refs.ani.run(()=>{
                               console.log('动画支持完毕')
                           });
            },
            
            magnify:function() {
                           this.$refs.ani.step({
                               scale: '1.5',
                           },{
                               timingFunction: 'ease-in',
                                duration: 1200
                           });
                           // 开始执行动画
                           this.$refs.ani.run(()=>{
                               console.log('动画支持完毕')
                           });
            },
            
            reduce:function() {
                           this.$refs.ani.step({
                               scale: '1',
                               //rotate: '0'
                           },{
                               timingFunction: 'ease-in',
                               duration: 1200
                           });
                           // 开始执行动画
                           this.$refs.ani.run(()=>{
                               console.log('动画支持完毕')
                           });
            },
            rotateLeft:function(){
                           this.$refs.ani.step({
                               rotate: '-90'
                           },
                           {
                               timingFunction: 'ease-in',
                               duration: 1200
                           });
                           // 开始执行动画
                           this.$refs.ani.run(()=>{
                               console.log('动画支持完毕')
                           });
            },
            rotateRight:function(){
                           this.$refs.ani.step({
                               rotate: '0'
                           },{
                               timingFunction: 'ease-in',
                               duration: 1200
                           });
                           // 开始执行动画
                           this.$refs.ani.run(()=>{
                               console.log('动画支持完毕')
                           });
            }
        }
    }
</script>

<style>
    .animation-element-wrapper {
        display: flex;
        width: 750rpx;
        height: 550rpx;
        padding-top: 150rpx;
        padding-bottom: 150rpx;
        flex-direction: row;
        justify-content: center;
        overflow: hidden;
        background-color: #ffffff;
    }

    .animation-element {
        width: 200rpx;
        height: 200rpx;
        background-color: #1AAD19;
    }
    
    .animation-buttons {
        padding:30rpx 0;
        width: 750rpx;
        /* height: 360rpx; */
    }
    
    .animation-button {
        float: left;
        width: 340rpx;
        margin: 15rpx 15rpx;
    }
    
    .transition{
                justify-content: center;
                align-items: center;
                width: 100px;
                height: 100px;
                border-radius: 5px;
                text-align: center;
                background-color: #4cd964;
                box-shadow: 0 0 5px 1px rgba(0,0,0,0.2);
    }
</style>

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

         对应的源码可以访问这里获取: https://github.com/liuhongdi/
         或: https://gitee.com/liuhongdi

说明:作者:刘宏缔 邮箱: [email protected]

三,测试效果:

四,查看hbuilderx的版本: 

标签:动画,ease,console,18,app,ani,duration,uni,refs
From: https://www.cnblogs.com/architectforest/p/17142028.html

相关文章

  • 使用appuploader怎么安装测试​
    原文链接:​​http://kxdang.com/topic/appuploader/iosdev90.html​​首先我们来看安装测试这个模块,注意按照上面提示内容操作。​​1.安装测试​​​​2.上传IPA​​进入“......
  • 记录--uni-app实现京东canvas拍照识图功能
    这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助最近公司出了一个新的功能模块(如下图),大提上可以描述为实现拍照完上传图片,拖动四方框拍照完成上传功能......
  • 如何快速开发一款外卖app?
    随着线上新零售app开发越来越成熟,外卖app开发的确是一个现有比较不错的选择。许多人不了解外卖app的开发,下面我们就来看看如何快速开发一款外卖app。一、外卖app开发......
  • h5与原生app通信的各种功能
    importconfigfrom'@/config/index';importcubeModulefrom'_public/CubeModule.json';const_MIDEA_COMMON='MideaCommon';//通用组件const_MIDEA_USER='M......
  • 学习安卓App开发的基本流程
    许多小伙伴想了解学习开发一个安卓系统的App大概需要什么流程,那我们简单看一下吧!第一、开发语言选择。语言其实只是开发实际应用的第一步,安卓开发的首选语言是Kotlin,次选......
  • iOS APP开发经验分享!
    一、学习iOS了解iOS的基本规范和设计准则,了解现在市场上主流的几款iPhone手机尺寸以及分辨率,弄清楚不同版本iPhone物理像素(pt)和逻辑像素(px)的关系了解不同尺寸屏幕的适配......
  • uniapp安卓本地文件读取(html5+)
    plus.io.resolveLocalFileSystemURL(                "_www/static/caise.json",//static下路径                    functi......
  • CCF 小明放学 201812-2
    弄一个时间轴分析比较好每次输入完剩余时间都转换为已经亮了多久然后加上已经经过的时间看现在是什么灯调用小明上学201812-1可以得到答案#include<iostream>using......
  • appium通过子节点定位父节点xpath
    https://blog.csdn.net/chushujin/article/details/109016922?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7......
  • 修复 K8s SSL/TLS 漏洞(CVE-2016-2183)指南
    作者:老Z,中电信数智科技有限公司山东分公司运维架构师,云原生爱好者,目前专注于云原生运维,云原生领域技术栈涉及Kubernetes、KubeSphere、DevOps、OpenStack、Ansible等。前......