当前位置: 首页 > article >正文

使用SCSS实现随机大小的方块在页面滚动

目录

一、scss中的插值语法

二、方块在界面上滚动的动画


一、scss中的插值语法

插值语法 #{}‌ 是一种动态注入变量或表达式到选择器、属性名、属性值等位置的机制

.类名:nth-child(n) 表示需同时满足为父元素的第n个元素且类名为给定条件 

 效果图:

<div class="parent"><div class="child2"></div><div class="child"></div><div class="child"></div><div class="child"></div></div>
//nth是针对父元素下所有子元素进行选择
$height: 400px; // 视口高度
.parent {width: 400px;height: #{$height}; // 背景容器高度为视口高度.child {width: 50px;height: 50px;background-color: pink;margin: 10px;}.child2 {width: 30px;height: 30px;}//表示类名为.child2且为parent的第一个元素.child2:nth-child(1) {background-color: #6dd5ed; // 白色背景,透明度0.05}@for $i from 2 through 4 {//父元素所有子元素的1-4:nth-child(#{$i}) {background-color: red; // 白色背景,透明度0.05}}
}

二、方块在界面上滚动的动画

示例图:

方块滚动

<div class="main"><div class="bg-container"><ng-container *ngFor="let item of countList"><div class="square"></div></ng-container></div>
</div>
// 基础配置
$bg-color: #ffd6e7; // 粉色背景
$square-count: 40; // 方块数量
$min-size: 2vmin; // 最小尺寸
$max-size: 10vmin; // 最大尺寸
$animation-duration: 20s; // 基础动画时长//背景方块
.main {width: 100%;height: 100%;// 容器样式.bg-container {position: fixed;top: 0;left: 0;width: 100%;height: 100%;overflow: hidden;}
}// 方块基础样式
.square {position: absolute;background: rgba(255, 255, 255, 0.3);border-radius: 10%;animation: float linear infinite;background: linear-gradient(to bottom, #ee9ca7, #ffdde1);opacity: 0;// 生成随机方块 random随机生成0-给定数值的随机数,左闭右开@for $i from 1 through $square-count {&:nth-child(#{$i}) {$size: random($max-size - $min-size) + $min-size;$delay: random(30) * 0.1s;$duration: 15 + random(20) * 0.1s;$startX: random(50) * 1vw;$endX: $startX + (random(40) - 20) * 1vw;$rotation: random(360) * 1deg;width: #{$size};height: #{$size};animation-delay: $delay;animation-duration: $duration;left: $startX;@keyframes float {0% {transform: translateY(110vh) rotate(0deg);opacity: 0;}10% {opacity: 0.7;}50% {opacity: 1;}90% {opacity: 0.7;}100% {transform: translateY(-10vh) translateX($endX) rotate($rotation);opacity: 0;}}}}
}

http://www.lryc.cn/news/2396491.html

相关文章:

  • AI 眼镜新纪元:贴片式TF卡与 SOC 芯片的黄金组合破局智能穿戴
  • 论文阅读(六)Open Set Video HOI detection from Action-centric Chain-of-Look Prompting
  • 算法学习--持续更新
  • Postman 发送 SOAP 请求步骤 归档
  • Python Day39 学习(复习日志Day4)
  • [Python] Python自动化:PyAutoGUI的基本操作
  • 课程介绍:《ReactNative基础与实战指南2025》
  • “候选对话链”(Candidate Dialogue Chain)概念
  • 应急响应靶机-web2-知攻善防实验室
  • comfyui利用 SkyReels-V2直接生成长视频本地部署问题总结 1
  • UV 包管理工具:替代 pip 的现代化解决方案
  • css3 新增属性/滤镜效果/裁剪元素/图片适应盒子/定义和使用变量/恢复默认initial
  • YOLOv8 实战指南:如何实现视频区域内的目标统计与计数
  • matlab实现VMD去噪、SVD去噪,源代码详解
  • SQLite软件架构与实现源代码浅析
  • JAVA实战开源项目:精简博客系统 (Vue+SpringBoot) 附源码
  • Flink SQL 编程详解:从入门到实战难题与解决方案
  • GO+RabbitMQ+Gin+Gorm+docker 部署 demo
  • 通过openpyxl在excel中插入散点图
  • 基于cornerstone3D的dicom影像浏览器 第二十五章 自定义VR调窗工具
  • 针对 Harmony-Cordova 性能优化,涵盖原生插件开发、线程管理和资源加载等关键场景
  • 【SCI论文实现】信息引导的高质量三维重建——系统架构设计 PYTHON
  • 经典面试题:一文了解常见的缓存问题
  • Vue3处理number输入框避免NaN
  • GC1267F:单相全波风扇电机预驱动芯片解析
  • Linux --进程状态
  • 如何设计一个支持线上线下的通用订单模块 —— 面向本地生活服务行业的架构思路
  • 智能手机上用Termux安装php+Nginx
  • 【线上故障排查】缓存穿透攻击的识别与布隆过滤器(面试题 + 3 步追问应对 + 案例分析)
  • Visual Studio 调试中 PDB 与图像不匹配