CSS开发技巧——行为技巧
CSS开发技巧——行为技巧
-
使用overflow-scrolling支持弹性滚动
iOS页面
非body元素
的滚动操作会非常卡(Android不会出现此情况),通过overflow-scrolling:touch
调用Safari原生滚动来支持弹性滚动,增加页面滚动的流畅度- 场景:iOS页面滚动
-
使用transform启动GPU硬件加速
有时执行动画可能会导致页面卡顿,可在特定元素中使用硬件加速来避免这个问题
- 场景:动画元素(绝对定位、同级中超过6个以上使用动画)
-
使用attr()抓取data-*
在标签上自定义属性
data-*
,通过attr()
获取其内容赋值到content
上-
场景:提示框
-
<div class="bruce flex-ct-y" data-title="使用attr()抓取节点属性"><a class="hover-tips btn-1" href="https://www.baidu.com" data-msg="Hello World">提示框</a><a class="hover-tips btn-2" href="https://www.baidu.com"></a> </div><style> .hover-tips {position: relative;padding: 0 20px;border-radius: 10px;height: 40px;background-color: #66f;line-height: 40px;color: #fff;& + .hover-tips {margin-top: 10px;}&.btn-1 {&::after {position: absolute;left: 0;top: 0;border-radius: 5px;width: 100%;height: 100%;background-color: rgba(#000, .5);opacity: 0;text-align: center;font-size: 12px;content: attr(data-msg);transition: all 300ms;}&:hover::after {left: calc(100% + 20px);opacity: 1;}}&.btn-2:empty::after {content: attr(href);} } </style>
-
-
使用:valid和:invalid校验表单
``使用伪类
:valid
和:invalid
配合pattern
校验表单输入的内容- 场景:表单校验
-
使用pointer-events禁用事件触发
通过
pointer-events:none
禁用事件触发(默认事件、冒泡事件、鼠标事件、键盘事件等),相当于``的disabled
-
场景:限时点击按钮(发送验证码倒计时)、事件冒泡禁用(多个元素重叠且自带事件、a标签跳转)
-
<div class="bruce flex-ct-x" data-title="使用pointer-events禁用事件触发"><a class="disabled-trigger" href="https://www.baidu.com">点我</a> </div><style> .disabled-trigger {padding: 0 20px;border-radius: 10px;height: 40px;background-color: #66f;pointer-events: none;line-height: 40px;color: #fff; } </style>
-
-
使用+或~美化选项框
``使用
+
或~
配合for
绑定radio
或checkbox
的选择行为-
场景:选项框美化、选中项增加选中样式
-
<div class="bruce flex-ct-x" data-title="使用+或~美化选项表单"><ul class="beauty-selection"><li><input id="fed-engineer" type="radio" name="radioName" hidden><label for="fed-engineer"></label><span>前端工程师</span></li><li><input id="bed-engineer" type="radio" name="radioName" hidden><label for="bed-engineer"></label><span>后端工程师</span></li><li><input id="fsd-engineer" type="radio" name="radioName" hidden><label for="fsd-engineer"></label><span>全栈工程师</span></li></ul> </div><style> .beauty-selection {display: flex;li {display: flex;align-items: center;& + li {margin-left: 20px;}}input:checked + label {background-color: #f90;}label {margin-right: 5px;padding: 2px;border: 1px solid #f90;border-radius: 100%;width: 18px;height: 18px;background-clip: content-box;cursor: pointer;transition: all 300ms;&:hover {border-color: #09f;background-color: #09f;box-shadow: 0 0 7px #09f;}}span {font-size: 16px;} } </style>
-
-
使用:focus-within分发冒泡响应
表单控件触发
focus
和blur
事件后往父元素进行冒泡,在父元素上通过:focus-within
捕获该冒泡事件来设置样式-
场景:登录注册弹框、表单校验、离屏导航、导航切换
-
<div class="bruce flex-ct-x" data-title="使用:focus-within分发冒泡响应"><form class="bubble-distribution"><h3>注册</h3><div class="accout"><input type="text" placeholder="请输入手机或邮箱" pattern="^1[3456789]\d{9}$|^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$" required><img src="https://b-gold-cdn.xitu.io/v3/static/img/greeting.1415c1c.png"></div><div class="password"><input type="password" placeholder="请输入密码(6到20位字符)" pattern="^[\dA-Za-z_]{6,20}$" required><img src="https://b-gold-cdn.xitu.io/v3/static/img/blindfold.58ce423.png"></div><div class="code"><input type="text" placeholder="请输入邀请码(6位数字)" pattern="^[\d]{6}$" maxLength="6" required><button type="button">查询</button><img src="https://b-gold-cdn.xitu.io/v3/static/img/greeting.1415c1c.png"></div><img src="https://b-gold-cdn.xitu.io/v3/static/img/normal.0447fe9.png"><ul><li><input id="male" type="radio" name="sex"><label for="male">Boy</label></li><li><input id="female" type="radio" name="sex"><label for="female">Girl</label></li></ul><button type="button">注册</button></form> </div><style> .bruce {background-color: #999; } .bubble-distribution {position: relative;margin-top: 50px;padding: 25px;border-radius: 2px;width: 320px;background-color: #fff;h3 {font-size: 16px;color: #333;}div {margin-top: 10px;}img {position: absolute;left: 50%;bottom: 100%;margin: 0 0 -20px -60px;width: 120px;}ul {display: flex;justify-content: space-between;align-items: center;margin-top: 10px;height: 30px;line-height: 30px;}li {position: relative;width: 45%;transition: all 300ms;&:focus-within {background: linear-gradient(90deg, #09f 50%, transparent 0) repeat-x,linear-gradient(90deg, #09f 50%, transparent 0) repeat-x,linear-gradient(0deg, #09f 50%, transparent 0) repeat-y,linear-gradient(0deg, #09f 50%, transparent 0) repeat-y;background-position: 0 0, 0 100%, 0 0, 100% 0;background-size: 8px 1px, 8px 1px, 1px 8px, 1px 8px;animation: move 500ms infinite linear;}}input[type=text],input[type=password] {padding: 10px;border: 1px solid #e9e9e9;border-radius: 2px;width: 100%;height: 40px;outline: none;transition: all 300ms;&:focus:valid {border-color: #09f;}&:focus:invalid {border-color: #f66;}}input[type=radio] {position: absolute;width: 0;height: 0;&:checked + label {border: 3px solid transparent;background-color: #09f;color: #fff;}}label {display: block;border-bottom: 1px solid #ccc;width: 100%;background-clip: padding-box;cursor: pointer;text-align: center;transition: all 300ms;}button {margin-top: 10px;border: none;border-radius: 2px;width: 100%;height: 40px;outline: none;background-color: #09f;cursor: pointer;color: #fff;transition: all 300ms;}.accout,.password,.code {img {display: none;margin-bottom: -27px;}&:focus-within {img {display: block;}& ~ img {display: none;}}}.code {display: flex;justify-content: space-between;button {margin-top: 0;}input {&:not(:placeholder-shown) {width: 70%;& + button {width: 25%;}}&:placeholder-shown {width: 100%;& + button {width: 0;opacity: 0;}}}} } @keyframes move {to {background-position: 6% 0, -6% 100%, 0 -6%, 100% 6%;} } </style>
-
-
使用:hover描绘鼠标跟随
将整个页面等比划分成小的单元格,每个单元格监听
:hover
,通过:hover
触发单元格的样式变化来描绘鼠标运动轨迹-
场景:鼠标跟随轨迹、水波纹、怪圈
-
.bruce(data-title="使用:hover描绘鼠标跟随")ul.mouse-following- for (var i = 0; i < 500; i++)li<style> @function random-num($max, $min: 0, $u: 1) {@return ($min + random($max)) * $u; } .mouse-following {display: flex;overflow: hidden;flex-wrap: wrap;height: 100%;cursor: pointer;li {position: relative;width: 30px;height: 30px;&::before {position: absolute;left: 0;right: 0;top: 0;bottom: 0;border-radius: 100%;background-color: transparent;content: "";transform: scale3d(.1, .1, 1);transition: all 500ms ease-in;}&:hover {&::before {transform: scale3d(1.8, 1.8, 1.8);transition: transform 0s;}}@for $i from 1 through 500 {&:nth-child(#{$i}):hover {&::before {background-color: rgba(random-num(255), random-num(255), random-num(255), .8);}}}} } </style>
-
-
使用max-height切换自动高度
通过
max-height
定义收起的最小高度和展开的最大高度,设置两者间的过渡切换-
场景:隐藏式子导航栏、悬浮式折叠面板
-
<div class="bruce flex-ct-x" data-title="使用max-height切换自动高度"><ul class="auto-height"><li><h3>列表1</h3><p>内容1<br>内容2<br>内容3<br>内容4</p></li><li><h3>列表2</h3><p>内容1<br>内容2<br>内容3<br>内容4</p></li><li><h3>列表3</h3><p>内容1<br>内容2<br>内容3<br>内容4</p></li></ul> </div><style> .auto-height {width: 300px;li {cursor: pointer;& + li {margin-top: 5px;}&:hover p {border-bottom-width: 1px;max-height: 600px;}}h3 {padding: 0 20px;height: 40px;background-color: #f66;cursor: pointer;line-height: 40px;font-size: 16px;color: #fff;}p {overflow: hidden;padding: 0 20px;border: 1px solid #f66;border-top: none;border-bottom-width: 0;max-height: 0;line-height: 30px;transition: all 500ms;} } </style>
-
-
使用transform模拟视差滚动
通过
background-attachment:fixed
或transform
让多层背景以不同的速度移动,形成立体的运动效果-
场景:页面滚动、视差滚动文字阴影、视差滚动文字虚影
-
<div class="bruce" data-title="使用transform模拟视差滚动"><ul class="parallax-scrolling"><li>translateZ(-1px)</li><li>translateZ(-2px)</li><li>translateZ(-3px)</li></ul><p>内容</p><ul class="parallax-scrolling"><li>translateZ(-1px)</li><li>translateZ(-2px)</li><li>translateZ(-3px)</li></ul> </div><style> $bg: "https://static.yangzw.vip/codepen/lake.jpg"; .bruce {overflow-x: hidden;overflow-y: auto;perspective: 1px;transform-style: preserve-3d;p {height: 300px;line-height: 300px;text-align: center;font-size: 20px;color: #f66;} } .parallax-scrolling {display: flex;justify-content: center;align-items: center;height: 1000px;background: url($bg) no-repeat center fixed;li {width: 500px;text-align: center;font-weight: bold;font-size: 60px;&:nth-child(1) {color: #f66;transform: translateZ(-1px);}&:nth-child(2) {color: #09f;transform: translateZ(-2px);}&:nth-child(3) {color: #3c9;transform: translateZ(-3px);}} } </style>
-
-
使用animation-delay保留动画起始帧
通过
transform-delay
或animation-delay
设置负值时延保留动画起始帧,让动画进入页面不用等待即可运行-
场景:开场动画
-
<div class="bruce flex-ct-x" data-title="使用animation-delay保留动画首帧"><ul class="initial-keyframe"><li></li><li></li><li></li></ul> </div><style> .initial-keyframe {position: relative;width: 100px;height: 100px;li {position: absolute;border-radius: 100%;width: 100%;height: 100%;background-color: #3c9;transform: rotate(0) translate(-80px, 0);animation: rotate 3s linear infinite;&:nth-child(2) {animation-delay: -1s;}&:nth-child(3) {animation-delay: -2s;}} } @keyframes rotate {to {transform: rotate(1turn) translate(-80px, 0);} } </style>
-
-
使用resize拉伸分栏
通过
resize
设置横向自由拉伸来调整目标元素的宽度-
场景:富文本编辑器、分栏阅读
-
<div class="bruce flex-ct-x" data-title="使用resize拉伸多列分栏"><div class="stretching-column"><div class="left"><div class="resize-bar"></div><div class="resize-line"></div><div class="resize-text">ABCDEFGHIJKLMNOPQRSTUVWXYZ</div></div><div class="right">ABCDEFGHIJKLMNOPQRSTUVWXYZ</div></div> </div><style> .stretching-column {overflow: hidden;border: 1px solid #09f;width: 600px;height: 300px;line-height: 20px;font-size: 16px;color: #f90;.left {overflow: hidden;float: left;position: relative;height: 100%;}.right {overflow: hidden;padding: 10px;height: 100%;background-color: #f0f0f0;word-break: break-all;}.resize-bar {overflow: scroll;width: 200px;height: 100%;opacity: 0;resize: horizontal;&::-webkit-scrollbar {width: 200px;height: 100%;}&:hover,&:active {& ~ .resize-line {border-left: 1px dashed #09f;}}}.resize-line {position: absolute;right: 0;top: 0;bottom: 0;border-left: 1px solid #ccc;border-right: 2px solid #f0f0f0;pointer-events: none;}.resize-text {overflow-x: hidden;position: absolute;left: 0;right: 5px;top: 0;bottom: 0;padding: 10px;word-break: break-all;} } </style>
-
相关文章:
CSS开发技巧——行为技巧
CSS开发技巧——行为技巧 使用overflow-scrolling支持弹性滚动 iOS页面非body元素的滚动操作会非常卡(Android不会出现此情况),通过overflow-scrolling:touch调用Safari原生滚动来支持弹性滚动,增加页面滚动的流畅度 场景:iOS页面滚动 使用t…...

PX4之代码结构
PX4开源飞控是目前主流的开源飞控项目,被很多公司作为飞控开发的参考。也广泛被用于现在流行的evtol验证机的飞控,进行初步的飞行验证。可能大多数AAM以及UAM都离不开PX4。 项目代码可以从github下载 $ git clone --recursive GitHub - PX4/PX4-Autopil…...

【C++11】可变参数模板(函数模板、类模板)
在C11之前,类模板和函数模板只能含有固定数量的模板参数。C11增强了模板功能,允许模板定义中包含0到任意个模板参数,这就是可变参数模板。可变参数模板的加入使得C11的功能变得更加强大,而由此也带来了许多神奇的用法。 可变参数模…...
centos安装高版本cmake
之前centos版本为cmake version 2.8.12.2采用yum remove卸载后重装还是这个版本,看来centos下面就是这个最新了,这说明centos煞笔。于是自己下载cmake包,然后安装。 官方cmake链接地址(3.16)(其他版本自己找,链接给你了) 1,wget下载 2,解压: tar -zxf cmake-3.16.0.…...

重温一下C#的时间类型,并简单写一个定时器功能
🎉🎉 时间是一个非常抽象的概念,本篇文章我们不深究目前电脑上的时候是如何保持全网同步。主要是讲讲在使用C#编程语言里的时间类型。最后使用定时任务简单写一个提醒功能,比如:每天10点准时打开一次csdn首页ÿ…...
MYSQL查询语句执行顺序
SQL语句定义的顺序 (1) SELECT (2)DISTINCT <select_list> (3) FROM <left_table> (4) <join_type> JOIN <right_table> (5) ON <join_condition> (6) WHERE <where_condition> (7) GROUP BY <group_by_list> (8) WITH {C…...

总结:电容在电路35个基本常识
1 电压源正负端接了一个电容,与电路并联,用于整流电路时,具有很好的滤波作用,当电压交变时,由于电容的充电作用,两端的电压不能突变,就保证了电压的平稳。 当用于电池电源时,具有交流…...

Kroger EDI 855 采购订单确认报文详解
本文着重讲述Kroger EDI项目中,供应商发给Kroger的X12 855EDI 规范报文(采购订单确认)解读。 在此前的文章如何读懂X12报文中,我们对X12已经做了详细的介绍,大家可以以此为基础,深入了解855采购订单确认报…...

HANA SDA-远程数据源访问
我们需要把其他系统的数据拿过来,到BW里和财务的数据集成。 HANA SDA就是不复制数据,建立虚拟表(virtual table)来映射到远程数据源。通过这个虚拟表访问其他系统的数据。 对虚拟表的操作现在也可以查询,更新ÿ…...
【AUTOSAR】:OS-Hook
OS-Hook OS-HookPINIC类型1、Os_ErrKernelPanic1.1、Os_HookCallPanicHook1.1.1、OS_PANICHOOK1.1.1.1、Os_PanicHook1.1.1.2、Os_Hal_CoreFreezeOs_Hal_NOPOS-Hook 延伸阅读 延伸阅读 PINIC类型 1、Os_ErrKernelPanic...
Open3d入门
目录 点云数据 1 主成分分析 1.1 Method 1.2 Results 2 表面法线估计 2.1 Method 2.2 Results 3 体素网格下采样 3.1 Method 3.2 Results 点云数据 常用数据下载(免积分) 1 主成分分析 1.1 Method 对点云进行主成分分析(PCA&…...

linux部署zookeeper
linux部署zookeeper 1、单机部署zk ZooKeeper服务器是用Java创建的,它需要在JVM上运行,所以需要使用JDK1.6及以上版本,一般都是jdk1.8。 选择自己安装本地的jdk,而不是centos自带的openjdk。 查看本地安装的jdk: j…...
Junit4升级Junit5汇总
Junit4升级Junit5汇总目录MockMvcBuildersUnnecessaryStubbingException目录 记录Junit4升级到Junit5中遇到的问题和结局方案 MockMvcBuilders 问题: 将Junit4的RunWith和Rule都改成ExtendWith后出现setup函数中MockMvcBuilders的参数不正确 ExtendWith({Spring…...

Axios二次封装和Api的解耦
目录 一、axios三种基本写法 二、axios的二次封装 三、Api的解耦 一、axios三种基本写法 1)get方法(是最简单的): 写法二: 2)post: 3)axios请求配置 默认是get请求,如…...
SpringAOP从入门到源码分析大全,学好AOP这一篇就够了(一)
文章目录系列文档索引一、认识AOP1、AOP的引入原因2、AOP常见使用场景日志场景统计场景安防场景性能场景3、AOP概念AOP 的概念Aspect 概念(切面)Join point 概念(连接点)Pointcut 概念(切入点)Advice 概念&…...

【单目标优化算法】樽海鞘群算法(Matlab代码实现)
💥💥💞💞欢迎来到本博客❤️❤️💥💥 🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。 ⛳️座右铭&a…...

手把手教你,解决C盘分区不足,C盘怎么扩大磁盘分区
由于在磁盘分区中,C盘是很重要的一个磁盘,为了保证C盘有足够的磁盘分区。其中扩大C盘分区很常见的操作之一。那么,C盘怎么扩大磁盘分区?在本文中,易我小编将全面地讲解C盘合并分区的方法。 一、为什么C盘怎么扩大磁盘分…...

Ethernet-APL——过程自动化的新黄金标准
| Ethernet-APL为终客户和设备制造商带来益处 Ethernet-APL(Advanced Physical Layer,高级物理层)是一种两线制以太网物理层,它使用了由IEEE 802.3cg所定义的10BASE-T1L,并采用了新的工艺制造规定,因此构成…...

LVGL Styles
LVGL StylesGet started按钮添加标签按钮添加风格滑动条值显示StylesSize stylesBackground stylesBorder stylesOutline stylesShadow stylesImage stylesArc stylesText stylesLine stylesGet started 按钮添加标签 /*** brief 按钮事件回调函数* param e */ void btn_eve…...

扬帆优配|联通港股创近两年新高!A股资源类股爆发,食品饮料领跌
今日上午,A股商场和港股商场均现较大起伏震动,临近上午收盘出现一波跳水,不过,到上午收盘,上证指数仍微涨0.10%,煤炭等资源类板块明显上涨。 港股商场上午走弱,科技股领跌。 沪指微涨0.10%资源…...
解决matlab两个库文件名冲突的问题
解决matlab两个库文件名冲突的问题 1、删除一个路径的文件(不推荐)2、改变优先级(让不想要的版本shadowed)3、更改文件名 添加一个库,发现总是调用另一个库的同名文件,这是由于路径中优先级问题。 which -…...

单板机8088C语言计划
计划将原来用汇编写的小程序,用C语言重新写一遍 计划2个月能完成 然后再试试,能不能用C写一下固件BootLoad 和一个类似Dos时代的Debug调试器...

Namespace 命名空间的使用
名字空间:划分更多的逻辑空间,有效避免名字冲突的问题 1.什么是命名空间 名字命名空间 namespace 名字空间名 {...} // 名字空间 n1 域 namespace n1 {// 全局变量int g_money 0;void save(int money){g_money money;}void pay(int money){g_money - m…...
PHP中文网文章内容提取免费API接口教程
接口简介: 提取PHP中文网指定文章内容。本接口仅做内容提取,未经作者授权请勿转载。 请求地址: https://cn.apihz.cn/api/caiji/phpzww.php 请求方式: POST或GET。 请求参数: 【名称】【参数】【必填】【说明】 【用…...

azure web app创建分步指南系列之二
为注册表授权托管标识 你创建的托管标识尚未获得从容器注册表中提取数据的授权。在此步骤中,你将启用授权。 返回容器注册表的管理页面: 在左侧导航菜单中,选择“访问控制 (IAM)”。选择“添加角色分配”。此屏幕截图显示了如何为容器注册表启用添加角色分配。在角色列表中…...

封装一个小程序选择器(可多选、单选、搜索)
组件 <template><view class"popup" v-show"show"><view class"bg" tap"cancelMultiple"></view><view class"selectMultiple"><view class"multipleBody"><view class&…...

11.4java语言执行浅析4
编译成字节码(.class 文件) 使用 javac 命令将源代码编译为 Java 字节码(bytecode) 它不是机器码,而是 JVM 能理解的中间语言(字节码),具有平台无关性。 编译过程简要࿱…...

累加法求数列通项公式
文章目录 前言如何判断注意事项适用类型方法介绍典例剖析对应练习 前言 累加法,顾名思义,就是多次相加的意思。求通项公式题型中,如果给定条件最终可以转化为 a n 1 − a n f ( n ) a_{n1}-a_nf(n) an1−anf(n)的形式,或者…...
接口性能优化
一、耗时统计 在做接口的性能优化时,最重要的是知道时间消耗在哪里。 可以用StopWatch,进行耗时统计。 详情见: https://blog.csdn.net/sinat_32502451/article/details/148350451 二、链路追踪 如果团队使用了Skywalking,可以…...

第3节 Node.js 创建第一个应用
Node.js 非常强大,只需动手写几行代码就可以构建出整个HTTP服务器。事实上,我们的Web应用以及对应的Web服务器基本上是一样的。 在我们创建Node.js第一个"Hello, World!"应用前,让我们先了解下Node.js应用是由哪几部分组成的&…...