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%资源…...

利用最小二乘法找圆心和半径
#include <iostream> #include <vector> #include <cmath> #include <Eigen/Dense> // 需安装Eigen库用于矩阵运算 // 定义点结构 struct Point { double x, y; Point(double x_, double y_) : x(x_), y(y_) {} }; // 最小二乘法求圆心和半径 …...

多模态2025:技术路线“神仙打架”,视频生成冲上云霄
文|魏琳华 编|王一粟 一场大会,聚集了中国多模态大模型的“半壁江山”。 智源大会2025为期两天的论坛中,汇集了学界、创业公司和大厂等三方的热门选手,关于多模态的集中讨论达到了前所未有的热度。其中,…...

Linux 文件类型,目录与路径,文件与目录管理
文件类型 后面的字符表示文件类型标志 普通文件:-(纯文本文件,二进制文件,数据格式文件) 如文本文件、图片、程序文件等。 目录文件:d(directory) 用来存放其他文件或子目录。 设备…...
CVPR 2025 MIMO: 支持视觉指代和像素grounding 的医学视觉语言模型
CVPR 2025 | MIMO:支持视觉指代和像素对齐的医学视觉语言模型 论文信息 标题:MIMO: A medical vision language model with visual referring multimodal input and pixel grounding multimodal output作者:Yanyuan Chen, Dexuan Xu, Yu Hu…...

从WWDC看苹果产品发展的规律
WWDC 是苹果公司一年一度面向全球开发者的盛会,其主题演讲展现了苹果在产品设计、技术路线、用户体验和生态系统构建上的核心理念与演进脉络。我们借助 ChatGPT Deep Research 工具,对过去十年 WWDC 主题演讲内容进行了系统化分析,形成了这份…...
【Linux】C语言执行shell指令
在C语言中执行Shell指令 在C语言中,有几种方法可以执行Shell指令: 1. 使用system()函数 这是最简单的方法,包含在stdlib.h头文件中: #include <stdlib.h>int main() {system("ls -l"); // 执行ls -l命令retu…...
Linux简单的操作
ls ls 查看当前目录 ll 查看详细内容 ls -a 查看所有的内容 ls --help 查看方法文档 pwd pwd 查看当前路径 cd cd 转路径 cd .. 转上一级路径 cd 名 转换路径 …...
连锁超市冷库节能解决方案:如何实现超市降本增效
在连锁超市冷库运营中,高能耗、设备损耗快、人工管理低效等问题长期困扰企业。御控冷库节能解决方案通过智能控制化霜、按需化霜、实时监控、故障诊断、自动预警、远程控制开关六大核心技术,实现年省电费15%-60%,且不改动原有装备、安装快捷、…...
渲染学进阶内容——模型
最近在写模组的时候发现渲染器里面离不开模型的定义,在渲染的第二篇文章中简单的讲解了一下关于模型部分的内容,其实不管是方块还是方块实体,都离不开模型的内容 🧱 一、CubeListBuilder 功能解析 CubeListBuilder 是 Minecraft Java 版模型系统的核心构建器,用于动态创…...

Scrapy-Redis分布式爬虫架构的可扩展性与容错性增强:基于微服务与容器化的解决方案
在大数据时代,海量数据的采集与处理成为企业和研究机构获取信息的关键环节。Scrapy-Redis作为一种经典的分布式爬虫架构,在处理大规模数据抓取任务时展现出强大的能力。然而,随着业务规模的不断扩大和数据抓取需求的日益复杂,传统…...