css实现正反翻页效果组件

File翻转组件:

<template>
    <div>
        <div class="flip-box" :style="{ 'height': height, 'width': width }">
            <!-- 前面盒子 -->
            <div :class="{'flip-front':playFlip}"
                 class="flip-item flip-item-front">
                    <slot name="front"></slot>
            </div>
            <!-- 后面盒子 -->
            <div :class="{'flip-back':playFlip}"
                 class="flip-item flip-item-back">
               <slot name="back"></slot>
            </div>
        </div>
        <!-- 切换按钮 -->
        <div class="txtCenter">
            <div @click="play" class="more_btn">{{playFlip ? '恢复默认' : '更多'}}</div>
        </div>
    </div>
</template>
<script setup lang="ts">
import { provide, readonly, ref } from 'vue'
const props = defineProps<{
  height: string
  width: string
}>()
const playFlip = ref(false);//是否切换
//切换
const play = () => {
    playFlip.value = !playFlip.value
}
</script>
<style scoped>
    .flip-box {
        position: relative;
    }
    .flip-item {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        transition: all 1s ease-in-out 0s;
        backface-visibility: hidden;
        box-sizing: border-box;
    }
 
    .flip-item-front {
        visibility: visible;
    }
 
    .flip-item-back {
        transform: rotateY(180deg);
        visibility: hidden;
    }

    .flip-front {
        visibility: hidden;
        transform: rotateY(180deg);
    }
 
    .flip-back {
        transform: rotateY(0deg);
        visibility: visible;
    }
    .txtCenter {
        text-align: center;
    }
    .more_btn {
        position: fixed;
        bottom: 20px;
        left: 50%;
        height: 38px;
        width: 110px;
        line-height: 36px;
        background-image: linear-gradient(180deg, rgba(107,230,255,0.50) 2%, rgba(15,102,120,0.50) 100%);
        border: 1px solid #87EAFF;
        border-radius: 4px;
        color: #fff;
        text-align: center;
        background-color: transparent;
        font-size: 16px;
        transform: translate(-50%,0);
        z-index: 999;
        cursor: pointer;
    }
</style>

组件使用:

//插槽内容
 const slots = {
      front: () => <Front/>,  //前页
      back: () => <Back/>, //后页
    }
<Flip v-slots={slots} width='480px' />
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值