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

帮人家做网站维护百度营稍

帮人家做网站维护,百度营稍,专门做美甲的网站,学做淘宝客网站Day 6 - Scroll Animation 1. 演示效果 2. 分析思路 布局 所有的内容进行水平垂直居中,可以使用**margin:0 auto;,也可以使用flex**布局: body {background-color: #efedd6;display: flex;flex-direction: column;justify-content: center…

Day 6 - Scroll Animation

1. 演示效果

QQ录屏20240213173506 -original-original

2. 分析思路

  • 布局

    所有的内容进行水平垂直居中,可以使用**margin:0 auto;,也可以使用flex**布局:

body {background-color: #efedd6;display: flex;flex-direction: column;justify-content: center;align-items: center;
}
  • 绑定滚动事件

    1. 滚动事件可以用事件监听addEventListener()绑定到 window 对象上(也可以绑定到document上)
    2. 触发滚动事件后,执行对应的代码函数,判断是否显示卡片
  • 判断是否显示卡片

    1. querySelectorAll()获取卡片元素,得到一个伪元素数组。
    2. forEach()方法,对每一个卡片元素判断是否显示。
    3. 显示原则:当卡片的顶部到达视图窗口的顶部的距离小于视图窗口的高度时,说明卡片到达视图窗口了,便可以显示出来。
    4. 此处用到了getBoundingClientRect()方法和Window.innerHeight属性,**MDN Web Docs**是这样解释的:

    Element.getBoundingClientRect()方法返回一个 DOMRect 对象,其提供了元素的大小及其相对于视口的位置。
    语法 > getBoundingClientRect() > 参数
    无。
    返回值
    返回值是一个 DOMRect 对象,是包含整个元素的最小矩形(包括 padding 和 border-width)。该对象使用 left、top、right、bottom、x、y、width 和 height 这几个以像素为单位的只读属性描述整个矩形的位置和大小。除了 width 和 height 以外的属性是相对于视图窗口的左上角来计算的。

img

该笔记参考自https://www.cnblogs.com/feixianxing/p/mini-web-project-scroll-animation-50-projects-50-days-GitHub-html-css-javascript-js.html

3. 代码实现

3.1. HTML

<!DOCTYPE html>
<html lang="zh-CN"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>第6个-滚动页面</title><link rel="stylesheet" href="./style.css" /></head><body><h1>Scroll to see the animation</h1><!-- 盒子的数量不限 --><div class="box"><h2>Content</h2></div><div class="box"><h2>Content</h2></div><div class="box"><h2>Content</h2></div><div class="box"><h2>Content</h2></div><div class="box"><h2>Content</h2></div><div class="box"><h2>Content</h2></div><div class="box"><h2>Content</h2></div><div class="box"><h2>Content</h2></div><div class="box"><h2>Content</h2></div><div class="box"><h2>Content</h2></div><div class="box"><h2>Content</h2></div><div class="box"><h2>Content</h2></div><div class="box"><h2>Content</h2></div><div class="box"><h2>Content</h2></div><script src="./script.js"></script></body>
</html>

3.2. CSS

* {box-sizing: border-box;
}
/* 设置垂直水平居中 */
body {background-color: #efedd6;display: flex;/* 设置主轴方向从上到下 */flex-direction: column;justify-content: center;align-items: center;
}/* 内容 */
.box {background-color: #4682b4;width: 400px;height: 200px;margin: 10px;display: flex;justify-content: center;align-items: center;color: #ffffff;font-size: 30px;border-radius: 10px;box-shadow: 2px 4px 5px rgba(0, 0, 0, 0.3);transform: translateX(400%);transition: transform 0.4s ease;
}
/* 内容为偶的左边出,奇数从右边出 */
.box:nth-of-type(even) {transform: translateX(-400%);/* 测试 *//* background-color: red; */
}
/* 添加show按钮后 content内容回来 */
.box.show {transform: translateX(0);
}

3.3. Javascript

// 获取卡片元素
const boxes = document.querySelectorAll(".box");// 设置事件监听
window.addEventListener("scroll", checkBoxes);// 调用函数
checkBoxes();// 定义函数checkBoxes
function checkBoxes() {const triggerBottom = (window.innerHeight / 5) * 4;// 遍历 判断每一个卡片元素是否显示boxes.forEach((box) => {const boxTop = box.getBoundingClientRect().top;// 判断是否显示卡片// 当卡片的顶部到达视图窗口的顶部的距离小于视图窗口的高度时,// 说明卡片到达视图窗口了,便可以显示出来。if (boxTop < triggerBottom) {// 添加showbox.classList.add("show");} else {// 删除粗showbox.classList.remove("show");}});
}
http://www.tj-hxxt.cn/news/92361.html

相关文章:

  • 商业网站建设案例课程百度seo排名优化软件化
  • 东莞公司注册地址关键词优化心得
  • dw做网站首页怎么做长沙网站托管seo优化公司
  • 福州免费网站建站模板石家庄seo排名公司
  • 网上建设网站需要做的工作百度站长平台电脑版
  • 建设物业公司网站网络销售推广是做什么的具体
  • 成品网站源码1688danji6友情链接买卖
  • 温州网站推广站建设厦门网页搜索排名提升
  • 亚洲男女做暖网站软文推广哪个平台好
  • 济宁广告公司网站建设小姐关键词代发排名
  • 网站手机端制作软件湖北seo网站推广
  • 做网页做网站的技术人才江苏营销型网站建设
  • ai可以用来做网站吗网络服务器地址怎么查
  • 只做恐怖片的网站磁力兔子
  • 医院网站必须建设吗推广文章的注意事项
  • 网站进度表网站优化包括哪些
  • 哈尔滨+做网站公司有哪些二级域名查询网站
  • 如何做校园网站怎么营销自己的产品
  • 服务器做网站用什么环境好seo公司
  • 网站优化价格jsurl转码
  • asp网站关键字优化网站排名公司
  • 在线编辑图片的网站有哪些seo在线优化网站
  • 帝国cms怎么做网站网站维护一年一般多少钱?
  • 网站做防伪查询代码新泰网站设计
  • asp网站攻击深圳seo优化seo优化
  • 网站制作公司茂名b2b平台有哪些网站
  • 邢台建设局网站搜索引擎下载入口
  • 副业做网站软件杭州上城区抖音seo如何
  • 响应式网站注意事项seo推广的常见目的有
  • 云南放心seo整站优化app运营推广是干什么