css+视频 --- 文字烟雾出场效果

在这里插入图片描述

原厂地址:https://www.youtube.com/watch?v=lx3UtGiRcYA
烟雾素材:https://www.wlittleyang.com/_nuxt/videos/ed1872e.mp4

使用动画@keyframe 来控制“唯一的wataru制作”的显示效果

@keyframe animate {
    0% {
        opacity:0,/*一开始不显示,透明度为0*/
        transform: rotageY(90deg),/*以Y轴旋转90度*/
        filter:blur(10px),/*字体模糊10px*/ 
    }
    100% {
    	opacity:1, /*显示*/
        transform: rotateY(0), /*不旋转*/ 
        filter:blur(0),/*不模糊*/
    }
}

对所有 字体 使用动画 animate:

<body>
    <section>
        <video src="./smoke.mp4" muted autoplay></video>
        <h1>
            <span></span>
            <span></span>
            <span></span>
            <span>w</span>
            <span>a</span>
            <span>t</span>
            <span>a</span>
            <span>r</span>
            <span>u</span>
            <span></span>
            <span></span>
        </h1>
    </section>
</body>
h1 span {
    animation: animate 1s ease-in-out forward;// 使用animate动画,持续1s,快慢快速度,向前显示不循环
}

再对每个 字体 延迟显示:

h1 span:nth-child(1) {
	animation-delay:0.4s
}
h1 span:nth-child(2) {
	animation-delay:0.8s
}
...

延迟时间根据视频烟雾扩散的时间来均分,视频有 7s 左右,但烟雾扩散比较好用的是 4 s 左右,一个有 11 个span, 4 / 11 ≈ 0.4s。

video {
    object-fit:cover;/* video的内容的填充方式 */
}

CSS 与可替换元素

CSS 在某些情况下会对可替换元素做一些特殊处理,比如计算外边距(margin)和一些 auto 的具体值。

需要注意的是,一部分(并非全部)可替换元素,其本身具有的尺寸和基线(baseline)会被一些 CSS 属性用到,加入计算之中,例如 vertical-align。只有可替换元素才能具有这种自带值。

控制内容框中的对象位置

某些CSS属性可用于指定 可替换元素中包含的内容对象 在该元素的盒区域内的位置或定位方式。这些属性的具体定义可以在 CSS Images Module Level 3CSS Images Module Level 4 规范中找到:

完整代码显示:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" type="text/css" href="./index.css">
</head>
<body>
    <section>
        <video src="./smoke.mp4" muted autoplay></video>
        <h1>
            <span></span>
            <span></span>
            <span></span>
            <span>w</span>
            <span>a</span>
            <span>t</span>
            <span>a</span>
            <span>r</span>
            <span>u</span>
            <span></span>
            <span></span>
        </h1>
    </section>
</body>
</html>
body {
    margin:0;
    padding:0;
}
section {
    height: 100vh;
    background-color: #333;
}
video {
    object-fit: cover;
    width: 100%;
}
h1 {
    margin:0;
    padding: 0;
    position: absolute;
    top:50%;
    transform: translateY(-50%);
    width: 100%;
    text-align: center;
    font-size:80px;
    word-spacing: .2em;
    font-family: sans-serif;
    color:#ddd;
    
}
h1 span {
    opacity: 0;
    display: inline-block;
    animation: animate 1.5s ease-in-out forwards;
}
@keyframes animate {
    0% {
        opacity:0;
        filter: blur(10px);
        transform: rotateY(-90deg);
    }
    100% {
        opacity: 1;
        filter: blur(0);
        transform:rotateY(0)
    }
}
h1 span:nth-child(1) {
    animation-delay: 0.4s;
}
h1 span:nth-child(2) {
    animation-delay: .8s;
}
h1 span:nth-child(3) {
    animation-delay: 1.2s;
}
h1 span:nth-child(4) {
    animation-delay: 1.6s;
}
h1 span:nth-child(5) {
    animation-delay: 2s;
}
h1 span:nth-child(6) {
    animation-delay: 2.4s;
}
h1 span:nth-child(7) {
    animation-delay: 2.8s;
}
h1 span:nth-child(8) {
    animation-delay: 3.2s;
}
h1 span:nth-child(9) {
    animation-delay: 3.6s;
}
h1 span:nth-child(10) {
    animation-delay: 4.0s;
}
h1 span:nth-child(11) {
    animation-delay: 4.4s;
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在vite.config.ts中适配postcss-pxtorem和amfe-flexible,需要进行如下配置: 1. 安装依赖 首先,需要安装postcss-pxtorem和amfe-flexible这两个库,可以使用npm或yarn进行安装: ``` npm install postcss-pxtorem amfe-flexible --save-dev ``` ``` yarn add postcss-pxtorem amfe-flexible --dev ``` 2. 配置vite.config.ts 在vite.config.ts中,需要添加一个postcss插件,并将amfe-flexible作为其参数传入,同时也需要配置postcss-pxtorem插件,代码如下: ```typescript import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; import postcssPxToRem from 'postcss-pxtorem'; export default defineConfig({ plugins: [ vue(), { name: 'postcss', async transform(css, id) { if (id.endsWith('.vue') || id.endsWith('.css')) { const { default: postcss } = await import('postcss'); const { default: flexible } = await import('amfe-flexible'); const processor = postcss([postcssPxToRem({ rootValue: 37.5, propList: ['*'], })]); const result = await processor.process(css, { from: id }); return { code: result.css, map: result.map, }; } }, enforce: 'post', }, ], }); ``` 这里使用了vite的postcss插件,该插件可以通过调用postcss的API来处理CSS文件。在transform函数中,首先判断当前文件的类型是否为.vue或.css,然后使用postcss-pxtorem将px转换成rem,其中rootValue为根元素的字体大小,propList为要转换的属性列表,这里设置为所有属性都转换。 同时,将amfe-flexible作为postcss插件的参数传入,这样就可以自适应不同屏幕尺寸。 需要注意的是,由于postcss插件是异步执行的,因此需要使用async/await来等待插件执行完成后再返回结果。 以上就是在vite.config.ts中适配postcss-pxtorem和amfe-flexible的方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值