凹下去的白色按钮

2023-11-03

先看效果:
在这里插入图片描述
再看代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>凹下去的按钮</title>
  <style>
    @import url("https://fonts.googleapis.com/css2?family=Comfortaa:wght@600&display=swap");
    :root {
      --highlight-left: 0;
      --pagination-width: 0;
    }

    html {
      height: 100%;
    }

    body {
      font-family: sans-serif;
      height: 100%;
      margin: 0;
      font-family: "Comfortaa", cursive;
      background-color: #eef3f7;
      user-select: none;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .radio-checked {
      position: relative;
      font-size: 34px;
      letter-spacing: 1px;
      box-shadow: -6px -5px 14px 3px #fff, 7px 7px 12px 2px #d0d8e3;
      border-radius: 70px;
    }
    .radio-checked_input {
      display: none;
    }
    .radio-checked_input:checked + .radio-checked_label--on {
      color: #47cf73;
      text-shadow: 0 0 7px rgba(71, 207, 115, 0.6);
    }
    .radio-checked_input:checked + .radio-checked_label--off {
      color: #ff3c41;
      text-shadow: 0 0 7px rgba(255, 60, 65, 0.6);
    }
    .radio-checked_input:checked + .radio-checked_label:before {
      display: none;
    }
    .radio-checked_label {
      cursor: pointer;
      display: inline-block;
      padding: 20px 25px 15px;
      line-height: 1;
      border-radius: 3rem;
      color: #acb2c0;
      transition: all 150ms ease-in-out;
    }
    .radio-checked_label:before {
      content: "";
      position: absolute;
      left: 0;
      top: 0;
      right: 0;
      bottom: 0;
      display: block;
    }
    .radio-checked_container {
      position: relative;
    }
    .radio-checked_highlight {
      position: absolute;
      left: 0;
      bottom: 0;
      width: var(--pagination-width);
      height: 100%;
      border-radius: 70px;
      box-shadow: inset -5px -5px 10px 4px #fff, inset -2px 6px 8px 6px #d0d8e3;
      background: #eef3f7;
      transition: all 0.6s ease;
      transform: translateX(var(--highlight-left));
    }

    .svg {
      position: absolute;
      top: -50%;
      bottom: -50%;
      pointer-events: none;
    }
    .svg_icon {
      width: auto;
      height: 100%;
    }
    .svg--right {
      left: 100%;
    }
    .svg--left {
      right: 100%;
    }
  </style>
</head>
<body>
<div class="radio-checked">
  <div class="radio-checked_highlight"></div>
  <div class="radio-checked_container">
    <input checked="checked" class="radio-checked_input" id="on" name="status" type="radio" value="on" /><label class="radio-checked_label radio-checked_label--on" for="on"> On</label><input class="radio-checked_input" id="off" name="status" type="radio" value="off" /><label class="radio-checked_label radio-checked_label--off" for="off">Off</label>
  </div>
</div>
</body>
<script>
  let root = document.documentElement;
  let color = ["#47cf73", "#7f71fe", "#1A3AF8", "#47cf73"];
  var animateDur = "1.4s";

  window.onload = function () {
    let activeChecked = document.querySelector(
            ".radio-checked_input:checked + .radio-checked_label"
    );
    let left = activeChecked.offsetLeft;
    let width = activeChecked.offsetWidth;
    animation(left, width);
  };

  document
          .querySelectorAll(".radio-checked_label")
          .forEach((t) => t.addEventListener("click", onChecked));

  function onChecked(e) {
    let left = e.target.offsetLeft;
    let width = e.target.offsetWidth;
    animation(left, width);
  }
  var bool = true;
  function animation(left, width) {
    root.style.setProperty("--pagination-width", width + "px");
    root.style.setProperty("--highlight-left", left + "px");
    (bool = !bool) ? svgCreate("right") : svgCreate("left");
  }

  function svgCreate(position) {
    let svgLeft =
            `<svg class="svg_icon" fill="none" viewBox="0 0 132 140" xmlns="http://www.w3.org/2000/svg">
<path d="M110 50.4209L68.7302 25.4209" id="Line1"/>
<path d="M110 59.498L45.9597 54.498" id="Line2"/>
<path d="M110 70.4824L46.1323 87.4824" id="Line3"/>
<path d="M110 79.3584L73.3484 113.358" id="Line4"/>
<path d="M110 73.4473L34.2236 110.447" id="Line5"/>
<path d="M110 64.499L24.0356 70.499" id="Line6"/>
<path d="M110 54.4736L39.8398 31.4736" id="Line7"/>
<path d="M110 56.4893L23.8953 38.4893" id="Line8"/>
<path d="M110 67.4893L21.1013 85.4893" id="Line9"/>
<path d="M110 85.2861L85.4102 118.286" id="Line10"/>
<path d="M110 76.4111L50.2839 116.411" id="Line11"/>
<path d="M110 61.4995L18.9907 59.4307" id="Line12"/>

		<g> <g> <g class="svg_obj"> <path d="M14.6324 5.25L20.9832 16.25C21.5606 17.25 20.8389 18.5 19.6842 18.5H6.98249C5.82778 18.5 5.10609 17.25 5.68344 16.25L12.0343 5.25C12.6116 4.25 14.055 4.25 14.6324 5.25Z" fill="none" stroke-linecap="square" stroke-linejoin="round" stroke-width="3" stroke=` +
            color[Math.floor(Math.random() * 4)] +
            `></path>
		</g> <animateMotion begin="0s" dur=` +
            animateDur +
            ` repeatCount="1"> <mpath xlink:href="#Line` +
            Math.floor(Math.random() * 6 + 6) +
            `"></mpath> </animateMotion> </g> </g> <g> <g> <g class="svg_obj"> <circle cx="12" cy="11" r="6.5" stroke-width="3" stroke=` +
            color[Math.floor(Math.random() * 4)] +
            `></circle> </g> <animateMotion begin="0s" dur=` +
            animateDur +
            ` repeatCount="1"> <mpath xlink:href="#Line` +
            Math.floor(Math.random() * 12 + 1) +
            `"></mpath> </animateMotion> </g> </g>
		 <g> <g> <g class="svg_obj"> <circle cx="12" cy="11" r="6.5" stroke-width="3" stroke=` +
            color[Math.floor(Math.random() * 4)] +
            `></circle> </g> <animateMotion begin="0s" dur=` +
            animateDur +
            ` repeatCount="1"> <mpath xlink:href="#Line` +
            Math.floor(Math.random() * 6 + 1) +
            `"></mpath> </animateMotion> </g> </g>
		 <g> <g> <g class="svg_obj"> <circle cx="12" cy="11" r="6.5" stroke-width="3" stroke=` +
            color[Math.floor(Math.random() * 4) + 1] +
            `></circle> </g> <animateMotion begin="0s" dur=` +
            animateDur +
            ` repeatCount="1"> <mpath xlink:href="#Line` +
            Math.floor(Math.random() * 12 + 1) +
            `"></mpath> </animateMotion> </g> </g>
		</svg>`;
    let svgRight =
            `<svg class="svg_icon" fill="none" viewBox="0 0 132 140"  xmlns="http://www.w3.org/2000/svg" >
<path d="M20 54.6191L64.6763 20.6191" id="Line13"/>
<path d="M20 56.5518L97.7788 20.5518" id="Line14"/>
<path d="M20 58.5176L90.8684 40.5176" id="Line15"/>
<path d="M20 63.5L111.989 61.5" id="Line16"/>
<path d="M20 69.5029L100.053 77.5029" id="Line17"/>
<path d="M20 73.5166L105.127 94.5166" id="Line18"/>
<path d="M20 77.5479L91.2126 108.548" id="Line19"/>
<path d="M20 80.6191L58.3235 108.619" id="Line20"/>
<path d="M20 83.7598L42.4385 114.76" id="Line21"/>
<path d="M20 66.5L98.0205 69.5" id="Line22"/>
<path d="M20 60.5049L102.93 49.5049" id="Line23"/>
<path d="M20 75.5303L83.1702 96.5303" id="Line24"/>

		<g> <g> <g class="svg_obj"> <path d="M14.6324 5.25L20.9832 16.25C21.5606 17.25 20.8389 18.5 19.6842 18.5H6.98249C5.82778 18.5 5.10609 17.25 5.68344 16.25L12.0343 5.25C12.6116 4.25 14.055 4.25 14.6324 5.25Z" fill="none" stroke-linecap="square" stroke-linejoin="round" stroke-width="3" stroke="#d0d8e3"></path>
		</g> <animateMotion begin="0s" dur=` +
            animateDur +
            ` repeatCount="1"> <mpath xlink:href="#Line` +
            Math.floor(Math.random() * 12 + 13) +
            `"></mpath> </animateMotion> </g> </g>

		<g> <g> <g class="svg_obj"> <path d="M17.2394 3L7.6162 18.2116M5 5.51355L20.2116 15.1367" stroke="#ff3c41" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/> </g> <animateMotion begin="0s" dur=` +
            animateDur +
            ` repeatCount="1"> <mpath xlink:href="#Line` +
            Math.floor(Math.random() * 12 + 13) +
            `"></mpath> </animateMotion> </g> </g>
		<g> <g> <g class="svg_obj"> <path d="M17.2394 3L7.6162 18.2116M5 5.51355L20.2116 15.1367" stroke="#acb2c0" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/> </g> <animateMotion begin="0s" dur=` +
            animateDur +
            ` repeatCount="1"> <mpath xlink:href="#Line` +
            Math.floor(Math.random() * 12 + 13) +
            `"></mpath> </animateMotion> </g> </g>
		</svg>`;

    let span = document.createElement("span");
    let radioChecked = document.querySelector(".radio-checked");
    span.className = "svg svg--" + position;
    if (position === "left") {
      span.innerHTML = svgLeft;
    } else {
      span.innerHTML = svgRight;
    }

    setTimeout(function () {
      radioChecked.appendChild(span);
    }, 400);
    setTimeout(function () {
      span.remove();
    }, 1500);
  }

</script>
</html>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

凹下去的白色按钮 的相关文章

随机推荐

  • mysql下载地址

    点击下载
  • Java赛马程序

    编写一个多线程的控制程序 称为赛马程序 创建分别代表两匹马的两个线程 并将它们设置为高低不同的优先级 并以进度条的形式显示赛马过程 没几天Java要考试了 紧急学习一下再把之前参考 10条消息 Java多线程 进度条实现赛马实验 shall
  • 贪心算法:55.跳跃游戏(C++)

    class Solution public bool canJump vector
  • Ubuntu设置脚本、程序开机自启动

    Ubuntu设置脚本 程序开机自启动 方法1 修改 etc rc local 方法2 用update rc d命令添加开机执行脚本 方法3 使用 crontab 方法4 使用 systemd 服务 Centos 注 方法1 修改 etc r
  • 提交表单区别

    html按钮有两种
  • C++内存管理

    http blog csdn net zhanghefu article details 5003383 内存管理是C 最令人切齿痛恨的问题 也是C 最有争议的问题 C 高手从中获得了更好的性能 更大的自由 C 菜鸟的收获则是一遍一遍的检查
  • 深入理解AMBA总线——AXI原子访问机制和AXI响应

    本篇文章给大家讲解AXI协议的原子访问机制 1 Atomic访问机制 1 1 Atomic信号 众所周知 操作系统的很多机制需要底层硬件的支持 如并发 虚拟化等 随着多处理器的流行 arm也自然而然的要做其总线上加入和并发相关的信号 以满足
  • 【kubernetes系列】k8s ingress配置websocket支持

    背景 公司的后端同事在代码调试过程中需要上传一个文件 调用的websocket接口 了解同事需求和现象 浏览器上传文件一直卡主 通过浏览器调试模式发现无法正常获取websocket的连接 websocket的接口访问可以通过wscat命令
  • CTFHUB-Cookie注入

    Cookie Cookie 浏览器向服务器发送请求时发送cookie 或者服务器向浏览器附加cookie 就是将cookie附近在这里的 例如 Cookie user admin HackBar Load一下 BurpSuite等工具也可以
  • vuex固化插件的使用

    数据持久化 刷新页面 vuex里面数据丢失 清空 有时候我们需要把一些数据固话到本地 即使刷新也不能清空 第一步 需要先下载插件 npm install vuex persistedstate save 第二步 在 store index
  • linux配置SVN,添加用户,配置用户组的各个权限教程

    前言 今天组长要我给新员工添加svn 的权限 以及赋予他们权限访问指定的目录 于是就顺手写个教程吧 毕竟好记性不如烂笔头 一 xshell登陆服务器 用xshell登陆服务器 cd切换到服务器中svn的项目仓库目录中 然后切换到conf文件
  • java利用freemark和itext出pdf文件

    第一步导包
  • Navicat Premium

    一 简介 Navicat Premium 是一套数据库开发工具 让你从单一应用程序中同时连接 MySQL MariaDB SQL Server Oracle PostgreSQL 和 SQLite 数据库 它与 Amazon RDS Ama
  • 计算机基础汇总

    计算机基础汇总 时间复杂度 https blog csdn net qq 41523096 article details 82142747 数组与链表 https blog csdn net qq 25806863 article det
  • normalize.css在vue中使用

    css样式初始化 normalize在vue中使用 1 Normalize css只是一个很小的css文件 但它在磨人的HTML元素样式上提供了跨浏览器的高度一致性 相比于传统的CSS reset Normalize css是一种现代的 为
  • CUDA - 在CUDA C/C++中使用共享内存

    原文链接 Using Shared Memory in CUDA C C 文章目录 共享内存 线程同步 共享内存示例 静态共享内存 动态共享内存 共享内存bank冲突 配置共享内存数量 总结 在上一篇文章中 我研究了如何将一组线程的全局内存
  • F12复制返回的json

    第一步 打印返回的数据 然后打开控制台 第二步 在打印的res右键出现会出现Store as global variable 然后点击 出现temp 第三步 在控制台输入copy temp 第四步 这个时候已经复制好json了 直接粘贴到t
  • 计算除法java实现

    class Solution public double calcEquation List
  • ROS报错[joint_state_publisher_gui-1] process has died [pid 70747, exit code 1, cmd...

    1 报错 终端里运行 roslaunch mbot description display mbot launch 出现报错如下 joint state publisher gui 1 process has died pid 70747
  • 凹下去的白色按钮

    先看效果 再看代码