首页 > 其他分享 >html+css3+anime.js实现文字故障动画

html+css3+anime.js实现文字故障动画

时间:2023-10-19 10:27:28浏览次数:37  
标签:css3 info loading 100% box js html anime path

记录一个很酷的动画,效果如图:

 是基于html+css3+anime.js实现的,看了眼代码,其实是默认文字的div中定位了几个相同的文字块,利用clip-path这个属性去裁剪展示其中的一部分,用于展示故障的效果,动画则是使用anime.js去循环改变X与Y轴的位置,同时调整绘制的颜色,demo代码如下:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta
      name="viewport"
      content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0"
    />
    <meta name="referrer" content="no-referrer" />
    <title>demo</title>
  </head>
  <body>
    <div class="loading_box">
    <div class="loading_info">
      <div class="loading_info_text_lists">
        访问者接入
        <div class="loading_info_text loading_info_text1">访问者接入</div>
        <div class="loading_info_text loading_info_text2">访问者接入</div>
        <div class="loading_info_text loading_info_text3">访问者接入</div>
        <div class="loading_info_text loading_info_text4">访问者接入</div>
        <div class="loading_info_text loading_info_text5">访问者接入</div>
      </div>
      <div class="loading_info_text_lists">
        资料延展中
        <div class="loading_info_text loading_info_text1">资料延展中</div>
        <div class="loading_info_text loading_info_text2">资料延展中</div>
        <div class="loading_info_text loading_info_text3">资料延展中</div>
        <div class="loading_info_text loading_info_text4">资料延展中</div>
        <div class="loading_info_text loading_info_text5">资料延展中</div>
      </div>
    </div>
</div>
  </div>
  <style>
    html, body{
        margin: 0;
        padding: 0;
    }
    .loading_box{
        padding: 36px;
        box-sizing: border-box;
        background-color: rgb(39, 38, 38);
    }
    .loading_box .loading_info {
      font-size: 20px;
      line-height: 48px;
      color: rgb(159, 159, 159);
    }
    .loading_box .loading_info .loading_info_text_lists {
      position: relative;
      display: block;
      width: 160px;
      height: 48px;
    }
    .loading_box .loading_info .loading_info_text_lists:last-child {
      margin-left: 30px;
    }
    .loading_box .loading_info .loading_info_text_lists .loading_info_text {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      color: rgb(159, 159, 159);
    }
    .loading_box .loading_info .loading_info_text_lists .loading_info_text1 {
      -webkit-clip-path: polygon(0 0%, 100% 0%, 0 20%, 100% 20%);
      clip-path: polygon(0 0%, 100% 0%, 0 20%, 100% 20%);
    }
    .loading_box .loading_info .loading_info_text_lists .loading_info_text2 {
      -webkit-clip-path: polygon(0 20%, 100% 20%, 0 40%, 100% 40%);
      clip-path: polygon(0 20%, 100% 20%, 0 40%, 100% 40%);
    }
    .loading_box .loading_info .loading_info_text_lists .loading_info_text3 {
      -webkit-clip-path: polygon(0 40%, 100% 40%, 0 60%, 100% 60%);
      clip-path: polygon(0 40%, 100% 40%, 0 60%, 100% 60%);
    }
    .loading_box .loading_info .loading_info_text_lists .loading_info_text4 {
      -webkit-clip-path: polygon(0 60%, 100% 60%, 0 80%, 100% 80%);
      clip-path: polygon(0 60%, 100% 60%, 0 80%, 100% 80%);
    }
    .loading_box .loading_info .loading_info_text_lists .loading_info_text5 {
      -webkit-clip-path: polygon(0 80%, 100% 80%, 0 100%, 100% 100%);
      clip-path: polygon(0 80%, 100% 80%, 0 100%, 100% 100%);
    }
  </style>
  
  <script src="./jquery.js"></script>
  <script src="./anime.3.2.1.js"></script>
  <script>
    // 加载中文字故障动画
    let badWords = anime({
        targets: '.loading_info_text',
        translateX: [function () { return anime.random(-3, 3); }, function () { return anime.random(-3, 3); }],
        translateY: [function () { return anime.random(-2, 2); }, function () { return anime.random(-2, 2); }],
        color: function () { return 'rgb(' + anime.random(0, 255) + ',' + anime.random(0, 255) + ',' + anime.random(0, 255) + ')' },
        direction: 'alternate',
        opacity: [0, 1],
        loop: true,
        easing: 'easeInOutSine',
        delay: function () { return anime.random(0, 200); },
        duration: 200,
    })
  </script>
</html>

  

相关学习文章:

【clip-path】

https://www.cnblogs.com/pizitai/p/6188346.html

https://blog.csdn.net/qq_41490563/article/details/125526889?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-125526889-blog-127320123.235%5Ev38%5Epc_relevant_sort&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-125526889-blog-127320123.235%5Ev38%5Epc_relevant_sort&utm_relevant_index=1

【动画效果】

https://animejs.com/

标签:css3,info,loading,100%,box,js,html,anime,path
From: https://www.cnblogs.com/nangras/p/17774081.html

相关文章

  • laravel:异常时返回json(10.27.0)
    一,相关文档:https://learnku.com/docs/laravel/10.x/errors/14857#87364d二,php代码:1,app\exceptions\Handler.php增加以下一段:1234567891011//重写renderpublicfunctionrender($request,Throwable$e){    if(env('APP_DEBUG')){  ......
  • Node.js中常用的设计模式有哪些?
    本文由葡萄城技术团队首发。转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具、解决方案和服务,赋能开发者。设计模式简介设计模式是由经验丰富的程序员在日积月累中抽象出的用以解决通用问题的可复用解决方案,它提供了标准化的代码设计方案提升开发体验。Node.js作......
  • laravel:返回统一格式的json
    一,参考文档https://learnku.com/docs/laravel/10.x/responses/14850二,php代码1,App\extend\result\Result.php1234567891011121314151617181920212223242526272829303132333435<?php/*   统一格式的返回json数据*/na......
  • IDEA 出现 Cannot resolve method getParameter() in JSP 解决方法
    原链接java-CannotresolvemethodgetParameter()inJSP-StackOverflowIDEA中出现下图情况,版本IDEA2022.2.3。此方法大概率可用,如果帮到你请点个赞吧~  1.我们右键当前项目,选择进入"OpenModuleSettings",如下图2.进入下图界面后,点击下图加号弹出二级菜单,在通......
  • 常用JS加密/解密类型以及案例
    简介这里给大家汇总常用不常用的JS加密案例,免得大家用的时候到处去找例子。正题对称加密:替代字符表示法:使用Base64或类似的编码对数据进行简单的转换,不过这并不是真正的加密,而只是一种表示形式的转换。<!DOCTYPEhtml><html><body><h2>Base64编码示例</h2><p>原始文本:Hello......
  • vue项目运行内存不足 JS stacktrace
     因为node配置的环境变量默认是4096,如果vue项目过大,可能就会导致保存的时候,项目死掉。解决办法:1、我的电脑右键属性 2、搜索环境变量,点击编辑系统环境变量 3、点击环境变量4、更改默认值......
  • 认识HTML基础标签
    一文本标题<h1></h1><h2></h2>...<h6></h6>文本标题默认加粗,竖着排列,垂直有缝隙,文本大小从h1到h6由大到小<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport......
  • TS 踩坑笔记: 箭头函数添加泛型报错(Error: JSX element ‘T’ has no corresponding
    前言今天给大家分享一个在React项目中使用TypeScript遇到的错误项目背景React+TS的项目配置,项目中关于React组件的使用.tsx后缀,其他单纯的文件使用.ts后缀问题描述在React组件附近定义泛型的箭头函数时产生TS报错警告,原本以为是语法写错了但是实际上在.t......
  • vue 动态引入 js 文件
    在目录比如utils/options/下面建不同名字的js,再根据 this.type变量的值动态引入。(注意this.type变量的值要和相对应的js文件名一致onLoad(options){this.type=options&&options.typeconstfile=require(`@/utils/options/${this.type}.js`)t......
  • JS 通过年份获取月,季度,半年度,年度
    ​ 功能描述:实例化一个函数,给函数内传递不同的参数,获取从起始年份到现在年度所有的月份,季度,半年度,年度动态演示  ---------正文代码开始--------1.封装函数 createMonth注:此代码可直接复制黏贴使用functioncreateMonth(){lettypeText="";lettoday=ne......