3D图片动画效果组件封装

1.效果

3D图片动画效果

2.组件部分

javascript 复制代码
import "./index.less"


/**
 * 3D图片动画效果
 * @pictures: 图片数组[封面,英雄,标题]
 */
export const Picture3D = (props: any) => {
    console.log("3D图片动画效果", props)

    return <div
        className='picture3D'
        onClick={props.onClick}
        onMouseEnter={props.onMouseEnter}
        style={{
            width: props.width || "100%",
            height: props.height || "100%",
        }}
    >
        {/* 封面 */}
        <img src={props.pictures && (props.pictures[0] || "")} class="cover" />
        {/* 英雄 */}
        <img src={props.pictures && (props.pictures[1] || "")} class="hero" />
        {/* 标题 */}
        <img src={props.pictures && (props.pictures[2] || "")} class="title" />
    </div>
};

3. css样式部分

css 复制代码
// 3D图片动画效果
.picture3D {
    // width: 300px;
    // height: 500px;
    position: relative;

    & img {
        position: absolute;
        left: 0;
        width: 100%;
        /* 因为图片的效果是有过渡的,我们在这里也统一设置一下 */
        transition: 0.5s;
        height: 100%;
        width: 100%;
    }

    .cover {
        height: 100%;
        z-index: 1;
    }

    .hero {
        height: 100%;
        z-index: 2;
        /* 英雄在最初是不可见的 */
        opacity: 0;
    }

    .title {
        z-index: 3;
    }
}

.picture3D:hover .cover {
    /* 设置旋转 3D透视 */
    transform: perspective(500px) rotateX(25deg);
    /* 设置阴影 */
    box-shadow: 0 35px 35px -8px rgba(0, 0, 0, 0.75);
}

.picture3D:hover .hero {
    /* 透明度设置为不透明 */
    opacity: 1;
    /* 同样设置 3D 效果,然后横向不移动,纵向向上移动 50px,z 轴上靠近我们的眼睛一点设置 50px */
    transform: perspective(500px) translate3d(0, -50px, 50px);
}

.picture3D:hover .title {
    /* 设置 3D 效果,,然后横向不移动,纵向向上移动 25px,z 轴上靠近我们的眼睛一点设置 50px */
    transform: perspective(500px) translate3d(0, -25px, 50px);
}

4. 组件使用

javascript 复制代码
import { observer } from 'mobx-react';
import './index.less';
import { Picture3D } from '@/components/MyComponents/index'; // 引用组件






export default observer((props: any) => {




  return <div className={`report bg-white dark:bg-black text-black dark:text-white`}>
    {/* 组件使用传值 */}
    <Picture3D
      width={300}
      height={500}
      onClick={() => { console.log('点击了') }}
      pictures={[require('@/assets/3.webp'), require('@/assets/8.png'), require('@/assets/1.png')]}
    />
  </div>

}) 
相关推荐
2301_800256118 小时前
关系数据库小测练习笔记(1)
1024程序员节
金融小师妹18 小时前
基于多源政策信号解析与量化因子的“12月降息预期降温”重构及黄金敏感性分析
人工智能·深度学习·1024程序员节
GIS数据转换器1 天前
基于GIS的智慧旅游调度指挥平台
运维·人工智能·物联网·无人机·旅游·1024程序员节
南方的狮子先生1 天前
【C++】C++文件读写
java·开发语言·数据结构·c++·算法·1024程序员节
Neil今天也要学习2 天前
永磁同步电机无速度算法--基于三阶LESO的反电动势观测器
算法·1024程序员节
开开心心_Every2 天前
专业视频修复软件,简单操作效果好
学习·elasticsearch·pdf·excel·音视频·memcache·1024程序员节
liu****3 天前
16.udp_socket(三)
linux·开发语言·数据结构·c++·1024程序员节
草莓熊Lotso3 天前
《算法闯关指南:优选算法--位运算》--38.消失的两个数字
服务器·c++·算法·1024程序员节
unable code4 天前
攻防世界-Misc-can_has_stdio?
网络安全·ctf·misc·1024程序员节
思茂信息4 天前
CST License(Flexnet)设置与问题处理方法
服务器·网络·单片机·3d·php·1024程序员节·cst