20231028-黑马web进阶-平面转换

文章目录

位移:translate

语法:transform:translate(水平移动距离,垂直移动距离);
取值(正负均可):
①像素单位数值
②百分比(参照物为盒子自身尺寸)
注意:
①X轴正向为右,Y轴正向为下
②translate()如果只给出一个值,表示X轴方向移动距离
③单独设置某个方向的移动距离:translateX()&translateY()

案例-双开门

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>平面转换-位移基本使用</title>
  <style>
    .father {
      width: 960px;
      height: 540px;
      margin: 100px auto;
      border: 1px solid black;
      background-color: blueviolet;
      overflow: hidden;
      /* 超出父级范围的隐藏 */
    }

    .sonLeft {
      width: 50%;
      height: 100%;
      float: left;
      background-color: aqua;
      transition: all 0.5s;
      /* 设置过渡效果,持续时间为0.5秒 */
    }

    .sonRight {
      width: 50%;
      height: 100%;
      float: right;
      background-color: skyblue;
      transition: all 0.5s;
      /* 设置过渡效果,持续时间为0.5秒 */
    }

    /* 定义鼠标悬停时子元素的样式 */
    .father:hover .sonLeft {
      transform: translate(-100%);
      /* 设置位移变换效果,将子元素向右下方位移75% */
    }

    .father:hover .sonRight {
      transform: translateX(100%);
      /* 设置位移变换效果,将子元素向右下方位移75% */
    }
  </style>
</head>

<body>
  <div class="father">
    <div class="sonLeft"></div>
    <div class="sonRight"></div>
  </div>
</body>

</html>

旋转

旋转:transform: rotate(角度deg);(角度正负均可)

转换原点:transform-origin:原点水平位置 原点垂直位置;(默认原点是盒子的中心点)
取值:
①方位名词:left top right bottom center
②像素单位数值
③百分比(参照盒子自身尺寸计算)

案例

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>平面转换-旋转</title>
  <style>
    .box {
      width: 200px;
      height: 200px;
      margin: 400px auto;
      background-color: aquamarine;
      transition: all 2s;
      /* 设置过渡效果,持续时间为2秒 */
      transform-origin: right bottom;
      /* 设置旋转的原点为盒子的右下角 */
    }

    /* 定义鼠标悬停时盒子的样式 */
    .box:hover {
      transform: rotate(360deg);
      /* 设置旋转变换效果,将盒子顺时针旋转360度(一圈) */
    }
  </style>
</head>

<body>
  <div class="box"></div>
</body>

</html>

多重转换

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>平面转换-多重转换</title>
  <style>
    .box {
      width: 800px;
      height: 200px;
      border: 1px solid black;
    }

    .circle {
      width: 200px;
      height: 200px;
      background-color: blueviolet;
      border-radius: 50%;
      transition: all 3s;
    }

    .box:hover .circle {
      transform: translate(600px) rotate(720deg);
      /* 注意:旋转会改变坐标轴向,多重转换如果涉及旋转往最后书写 */
    }
  </style>
</head>

<body>
  <div class="box">
    <div class="circle"></div>
  </div>
</body>

</html>

缩放

语法:transform:scale(x轴缩放倍数,y轴缩放倍数);
技巧:
一般情况下,只为scale设置一个值,表示x轴和y轴等比例缩放
transform:scale(缩放倍数);
scale值大于1表示放大,scale值小于1表示缩小

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>平面转换-缩放</title>
  <style>
    .box {
      width: 300px;
      height: 300px;
      background-color: blueviolet;
      border: 1px solid black;
      margin: 300px auto;
      overflow: hidden;
    }

    .btn {
      width: 50px;
      height: 50px;
      background-color: cadetblue;
      margin: 125px auto;
      border-radius: 50%;
      transform: scale(8);
      opacity: 0;
      transition: all 0.3s;
    }

    .box:hover .btn {
      transform: scale(1);
      opacity: 1;
    }
  </style>
</head>

<body>
  <div class="box">
    <div class="btn"></div>
  </div>
</body>

</html>

渐变background-image:linear-gradient(颜色1,颜色2,...);

常用:background-image:linear-gradient(transparent,rgba(0, 0, 0, .5));

相关推荐
遇到困难睡大觉哈哈1 天前
Harmony os 静态卡片(ArkTS + FormLink)详细介绍
前端·microsoft·harmonyos·鸿蒙
用户47949283569151 天前
Bun 卖身 Anthropic!尤雨溪神吐槽:OpenAI 你需要工具链吗?
前端·openai·bun
p***43481 天前
前端在移动端中的网络请求优化
前端
g***B7381 天前
前端在移动端中的Ionic
前端
拿破轮1 天前
使用通义灵码解决复杂正则表达式替换字符串的问题.
java·服务器·前端
whltaoin1 天前
【 Web认证 】Cookie、Session 与 JWT Token:Web 认证机制的原理、实现与对比
前端·web·jwt·cookie·session·认证机制
Aerelin1 天前
爬虫playwright入门讲解
前端·javascript·html·playwright
5***o5001 天前
前端在移动端中的NativeBase
前端
灵魂学者1 天前
Vue3.x —— 父子通信
前端·javascript·vue.js·github
1***Q7841 天前
前端跨域解决方案
前端