侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

CSS3实现王者荣耀匹配人员加载页面的方法

前端  /  管理员 发布于 7年前   162

玩过王者的应该都熟悉,这个页面的效果。为什么要实现这个效果了?

第一:王者这么火,电竞这么火。

第二:主要还是来学习 CSS3 的线性、径向渐变、旋转、缩放以及动画。

图形解析

1、背景(径向渐变)

2、玩家(player)加载动画(线性渐变)

3、背景镂空旋转正方形

4、正方形文字放大动画

5、文字按钮制作

下面我们按上述步骤实现

背景制作

background: radial-gradient(center, shape size, start-color, …, last-color);

shape 参数定义了形状。它可以是值 circle 或 ellipse。其中,circle 表示圆形,ellipse 表示椭圆形。默认值是 ellipse

<style>  .king{    position: relative;    height: 25rem;    width: 100%;    background:       radial-gradient(circle, #ccc, #161d4f 85%);  }</style><div class="king"></div>

CSS3线性、径向渐变、旋转、缩放、动画实现王者荣耀匹配人员加载动画

玩家加载

模块整体垂直居中,线性渐变。

background: linear-gradient(direction/angle, color-stop1, color-stop2, …);

direction/angle控制渐变方向/角度。

<style>....player-layout{  position: relative;  height: 8rem;  width: 100%;  background:     linear-gradient(to right, #212f46, #212f4670, #212f46);  top: 50%;  transform: translate(0,-50%);  z-index: 10;}</style><div class="king">  <div class="player-layout"></div></div>

CSS3线性、径向渐变、旋转、缩放、动画实现王者荣耀匹配人员加载动画

添加峡谷图片,背景线性渐变,旋转。添加边框,然后用 box-shadow 看起来发光效果。

<style>....center{  position: absolute;  height: 8rem;  width: 8rem;  top: 50%;  left: 50%;  transform:     translate(-50%, -50%) rotate(45deg);  background:     linear-gradient(90deg, #212f46, #5b99ff);  border: .3rem solid #55a9ef;  box-shadow: 0px 0px .8rem #88c0f0;  padding: .2rem;}.center img{  width: 100%;  height: 100%;}</style><div class="king">  <div class="player-layout">    <div class="center"><img src="../images/123123.jpg"></div>  </div></div>

CSS3线性、径向渐变、旋转、缩放、动画实现王者荣耀匹配人员加载动画

下面把10个玩家,分2组,放到峡谷图片两侧。

<style>.......group{  position: relative;  width: calc((100% - 13rem)/2);  top: 50%;  transform: translate(0, -50%);}.group1{  text-align: right;  float: left;}.group2{  text-align: left;  float: right;}.palyer{  width: 4rem;  height: 4rem;  display: inline-block;  background: url('../images/123123.jpg');  background-size: cover;  border: .3rem solid #55a9ef;  box-shadow: 0px 0px .8rem #88c0f0;}  </style>...<div class="player-layout">  <div class="group group1">    <div class="player1 palyer"></div>    <div class="player2 palyer"></div>    <div class="player3 palyer"></div>    <div class="player4 palyer"></div>    <div class="player5 palyer"></div>  </div>  <div class="group group2">    <div class="player6 palyer"></div>    <div class="player7 palyer"></div>    <div class="player8 palyer"></div>    <div class="player9 palyer"></div>    <div class="player10 palyer"></div>  </div>  <div class="center"><img src="../images/123123.jpg"></div></div>...

这里每组的宽度,运用了 calc() 来计算宽度,(100%-矩形对角线长度)/2。

中间是个边长等于8rem的正方形,所以:对角线长度 = 8rem的平方 x 2 然后再开方。这里矩形对角线长度我们约等于13rem。

我们来添加每位player边框加载动画

.player{  position: relative;  ...  ...  color: #fff;}.player::before,.player::after {  position: absolute;  content: '';  top: 0;  bottom: 0;  left: 0;  right: 0;  margin: -8%;  box-shadow: inset 0 0 0 .3rem;  animation: clipMe 6s linear infinite;}.player::before {  animation-delay: -3s;}@keyframes clipMe {  0%,  100% {    clip: rect(0, 4.8rem, 4.8rem, 4.3rem);  }  25% {    clip: rect(0px, 4.8rem, .3rem, 0);  }  50% {    clip: rect(0, .3rem, 4.8rem, 0);  }  75% {    clip: rect(4.3rem, 4.8rem, 4.8rem, 0rem);  }}

主要用到 clip 属性。

clip 属性剪裁绝对定位元素。

当一幅图像的尺寸大于包含它的元素时会发生什么呢?“clip” 属性允许您规定一个元素的可见尺寸,这样此元素就会被修剪并显示为这个形状。

唯一合法的形状值是:rect (top, right, bottom, left)

这个属性很好玩儿,有兴趣的可以好好研究一下。

最后我们给两个分组上面加高光效果

.group::before, .group::after{  position: absolute;  content: '';  background: linear-gradient(to right,#212f4602, #7499d7, #212f4602);  height: .3rem;  width: 10rem;}.group::before{  top: -1.5rem;}.group::after{  bottom: -1.5rem;}.group1::before{  right: 0;}.group1::after{  right: 5rem;}.group2::after{  left: 5rem;}

ok,玩家这块我们先修饰到这样,有兴趣的拉取源码继续码。

背景镂空旋转正方形

<div class="king">  <div class="player-layout">    ...  </div>  <div class="matrix"></div></div><style>.matrix{  position: absolute;  height: 17.6rem;  width: 17.6rem;  background: #008cf4;  top: 50%;  left: 50%;  transform:     translate(-50%, -50%) rotate(45deg);  z-index: 1;}</style>

这里的height为什么是17.6rem了?

这里也是计算通过勾股定理(a²+b²=c²)计算出来的啦。知道对角线就是容器的高度25rem,25x25/2再开方就得出了。

上方设了个醒目的颜色,把容器放到哪里,然后我们来美化一下它

<style>....border{  position: absolute;  height: 17.6rem;  width: 17.6rem;  text-align: center;}.border::before,.border::after{  position: absolute;  display: block;  width: 100%;  height: 2.5rem;  color: #fff;  background:     linear-gradient(to top,#212f4602, #7499d7);}.border1::before{  content: '     web前端扣群 784783012     ';}.border1::after{  bottom: 0;  content: '     跟 我 一 起     ';  transform: rotate(180deg);}.border2{  transform: rotate(90deg);}.border2::before{  content: '     学 习 前 端     ';}.border2::after{  bottom: 0;  content: '     让 你 秀 起 来     ';  transform: rotate(180deg);}</style>...<div class="matrix">  <div class="border border1"></div>  <div class="border border2"></div></div>

用两个div元素来制作边框,边框添加线性渐变样式

下面继续修饰一下镂空正方形,这里宽高,之前是17.6,由于加了border和padding,所以去掉。

.matrix{  position: absolute;  /* 修改宽高 */  height: 16.7rem;  width: 16.7rem;  top: 50%;  left: 50%;  transform: translate(-50%, -50%) rotate(45deg);  z-index: 1;  /* 添加边框,与间距 */  border: .1rem solid #7499d7;  padding: .4rem;}.border{  position: absolute;  /* 修改宽高 */  height: 16.7rem;  width: 16.7rem;  text-align: center;}

 

正方形文字放大动画

这里就做了文字阴影,缩放暂时没有实现,目前缩放会改变原有文字,所以必须重新copy一份文字,来做,有兴趣的可以去试试。

.border::before,.border::after{  ...  animation: text-an 1.5s linear infinite;}@keyframes text-an {  0%{    text-shadow: 0 0 0 #ffffff;  }  100% {    text-shadow: 0 -6rem .4rem #ffffff10;  }}

 

文字按钮制作

利用:before、:after伪类制作梯形。

<div class="king">  ...  <div class="button">确认</div></div><style>.button{  position: relative;  background: #3e3a31;  width: 6.5rem;  height: 2rem;  line-height: 2rem;  color: #fff;  top: 50%;  left: 50%;  transform: translate(-50%, -50%);  z-index: 11;  text-align: center;  cursor: pointer;}.button::before,.button::after{  position: absolute;  content: '';  display: inline-block;  width: 0;   height: 0;  border-width: 1.43rem;  border-style: solid;  border-color:    #3e3a31     transparent     transparent      transparent;}.button::before{  transform: rotate(-135deg);  left: -1.40rem;  top: -1.42rem;}.button::after{  transform: rotate(135deg);  right: -1.43rem;  top: -1.43rem;}</style>

本节文章就到此为止吧,还有一些细节的地方,大家可以在练习操作的时候优化。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


  • 上一条:
    CSS3 transforms应用于背景图像的解决方法
    下一条:
    浅谈css阻断合并及其他影响
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 使用 Alpine.js 排序插件对元素进行排序(0个评论)
    • 在js中使用jszip + file-saver实现批量下载OSS文件功能示例(0个评论)
    • 在vue中实现父页面按钮显示子组件中的el-dialog效果(0个评论)
    • 使用mock-server实现模拟接口对接流程步骤(0个评论)
    • vue项目打包程序实现把项目打包成一个exe可执行程序(0个评论)
    • 近期文章
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-06
    • 2017-07
    • 2017-08
    • 2017-09
    • 2017-10
    • 2017-11
    • 2018-03
    • 2018-04
    • 2018-05
    • 2018-06
    • 2018-09
    • 2018-11
    • 2018-12
    • 2019-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-04
    • 2021-05
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-09
    • 2023-10
    • 2023-11
    • 2023-12
    • 2024-01
    • 2024-02
    • 2024-03
    • 2024-04
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客