欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

uniapp實現(xiàn)紅包動畫效果代碼實例(vue3)

 更新時間:2024年01月22日 15:37:35   作者:X_JinCheng  
uniapp作為一種基于Vue.js的前端框架,實現(xiàn)了一套代碼多端運行的理念,成為了眾多開發(fā)者的首選,下面這篇文章主要給大家介紹了關(guān)于uniapp實現(xiàn)紅包動畫效果的相關(guān)資料,需要的朋友可以參考下

效果演示

首先安裝CSS動畫庫animate.css依賴

yarn add animate.css

打開main.ts文件引入

import 'animate.css'

這兩張圖片放入static文件夾下

用到的圖片red1.png

用到的圖片red2.png

紅包整體主要分三部分 紅包頭部 中部 底部

<template>
    <view>
        <button @tap="red = true">顯示紅包</button>
    </view>
    <!-- 紅包特效遮罩層 -->
    <view v-show="red" class="cover">
        <!-- 紅包整體 -->
        <view class="redBig animate__animated animate__bounceIn" :key="redIndex">
            <!-- 頭部 -->
            <view :animation="redHead" class="redBigHead">
                <image @tap="redHeadAnimation" class="" src="/static/red1.png" mode=""></image>
            </view>
            <!-- 中間 -->
            <view :animation="redMid" class="redBigMid">
                <view class="text1">
                    恭喜您獲得了
                </view>
                <view class="text2">
                    100.00
                </view>
                <view class="text3">
                    紅包余額可去錢包查詢
                </view>
            </view>
            <!-- 底部 -->
            <view class="redBigBottom">
                <!-- 打開紅包后展示 -->
                <view @tap="redBagAnimationRenew" v-show="redBottom" class="button animate__animated animate__bounceIn">
                    開心收下
                </view>
            </view>
        </view>
    </view>
</template>

使用uni.createAnimation()創(chuàng)建動畫實例并進行相關(guān)操作具體查看官方文檔

<script setup lang="ts">
    import {
        ref,
        getCurrentInstance
    } from 'vue'
    import {
        onShow
    } from '@dcloudio/uni-app'
    const {
        proxy
    } = getCurrentInstance() as any
    //紅包動畫
    let red = ref(false) //紅包顯示 
    let redIndex = ref(0) //紅包組件刷新
    onShow(() => {
        let animation = uni.createAnimation()
        proxy.animation = animation
    })


    //頭部動畫
    let redHead = ref({})

    function redHeadAnimation() {
        proxy.animation.translateY(-300).opacity(0).step({
            duration: 500,
            timingFunction: 'ease-in-out',
        })
        redHead.value = proxy.animation.export()
        redBottom.value = true
        setTimeout(() => {
            redMidAnimation()
        }, 300)
    }
    //中部動畫
    let redMid = ref({})

    function redMidAnimation() {
        proxy.animation.translateY(-120).opacity(1).step({
            duration: 500,
            timingFunction: 'ease-in-out',
        })
        redMid.value = proxy.animation.export()
    }
    //紅包底部按鈕顯示
    let redBottom = ref(false)
    //重置紅包
    function redBagAnimationRenew() {
        red.value = false
        redBottom.value = false
        redHead.value = {}
        redMid.value = {}
        redIndex.value++
    }
</script>

除了紅包底部 頭部和中部需要定位

<style lang="scss">
    .cover {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        right: 0;
        background: rgba(000, 000, 000, 0.5);
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .redBig {
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .redBigHead {
        position: absolute;
        z-index: 2;

        image {
            width: 550rpx;
            height: 440rpx;
        }
    }

    .redBigMid {
        width: 508rpx;
        height: 350rpx;
        background-color: #fff;
        border-radius: 24rpx;
        display: flex;
        flex-direction: column;
        align-items: center;
        color: #FF4545;
        position: absolute;
        z-index: 0;
        margin-top: 260rpx;
        opacity: 0;

        .text1 {
            margin-top: 20rpx;
            font-size: 32rpx;
        }

        .text2 {
            margin-top: 30rpx;
            font-size: 70rpx;
        }

        .text3 {
            margin-top: 30rpx;
        }
    }

    .redBigBottom {
        width: 550rpx;
        height: 331rpx;
        background-image: url('../../static/red2.png');
        background-size: 100% 100%;
        margin-top: 280rpx;
        z-index: 1;

        .button {
            background: linear-gradient(to bottom, #FEE3AD 50%, #FEB05C);
            color: #BC0D0D;
            margin-left: 84rpx;
            margin-right: 84rpx;
            padding-top: 30rpx;
            padding-bottom: 30rpx;
            border-radius: 100rpx;
            text-align: center;
            margin-top: 150rpx;
        }
    }
</style>

總結(jié) 

到此這篇關(guān)于uniapp實現(xiàn)紅包動畫效果的文章就介紹到這了,更多相關(guān)uniapp紅包動畫效果內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 如何用命令窗口的方式創(chuàng)建Vue項目

    如何用命令窗口的方式創(chuàng)建Vue項目

    這篇文章主要介紹了如何用命令窗口的方式創(chuàng)建Vue項目過程,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • Vuejs在v-for中,利用index來對第一項添加class的方法

    Vuejs在v-for中,利用index來對第一項添加class的方法

    下面小編就為大家分享一篇Vuejs在v-for中,利用index來對第一項添加class的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-03-03
  • Vue3.x源碼調(diào)試的實現(xiàn)方法

    Vue3.x源碼調(diào)試的實現(xiàn)方法

    這篇文章主要介紹了Vue3.x源碼調(diào)試的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-10-10
  • vue前端信息詳情頁模板梳理詳解

    vue前端信息詳情頁模板梳理詳解

    這篇文章主要為大家詳細介紹了vue前端信息詳情頁模板梳理,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • mpvue開發(fā)音頻類小程序踩坑和建議詳解

    mpvue開發(fā)音頻類小程序踩坑和建議詳解

    這篇文章主要介紹了mpvue開發(fā)音頻類小程序踩坑和建議詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-03-03
  • 餓了么UI中el-tree樹節(jié)點選中高亮的兩種常用方式(highlight-current屬性)

    餓了么UI中el-tree樹節(jié)點選中高亮的兩種常用方式(highlight-current屬性)

    最近新做的項目有用到Element-UI tree組件,下面這篇文章主要給大家介紹了關(guān)于餓了么UI中el-tree樹節(jié)點選中高亮的兩種常用方式(highlight-current屬性),文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-12-12
  • form?表單驗證是異步問題記錄(推薦)

    form?表單驗證是異步問題記錄(推薦)

    這篇文章主要介紹了form?表單驗證是異步問題記錄,通過實例代碼介紹了Promise.all 和 Promise.allSettled 區(qū)別,需要的朋友可以參考下
    2023-01-01
  • Vue 動態(tài)添加路由及生成菜單的方法示例

    Vue 動態(tài)添加路由及生成菜單的方法示例

    這篇文章主要介紹了Vue 動態(tài)添加路由及生成菜單的方法示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-06-06
  • 說說Vue.js中的functional函數(shù)化組件的使用

    說說Vue.js中的functional函數(shù)化組件的使用

    這篇文章主要介紹了說說Vue.js中的functional函數(shù)化組件的使用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-02-02
  • vue-swiper的使用教程

    vue-swiper的使用教程

    swiper是我之前做前端頁面會用到的一個插件,我自己認為是非常好用的。這篇文章給大家介紹vue-swiper的使用教程,感興趣的朋友一起看看吧
    2018-08-08

最新評論