每日CSS_滚动页面动画效果

2021_1_13

源码链接

1. 代码解析

1.1 html 代码片段

<section>
<h2>开 始 滑 动</h2>
</section>
<div class="box">
<h2 class="text1">来看看 滑动效果呗! </h2>
<h2 class="text2">我是向左</h2>
<h2 class="text3">我是向右 (#^.^#)</h2>
<img src="logo.jpg" class="logo">
</div>
<div class="box2">
<h2 class="text4">来看看滑动效果呗! </h2>
<h2 class="text5">代码在最后哦</h2>
<h2 class="text6">滑动效果是啥? </h2>
</div>

共三个片段, 每个片段占 100vh, 也就是网页高度

1.2 script 代码片段

  gsap.timeline({
scrollTrigger: {
trigger: '.box',
// 起点
start: 'center center',
// 终点
end: 'bottom top',
// 动画标记
// markers: true,
// 将动画关联到滑轮上
scrub: true,
pin: true,
}
})
.from('.text1', {x: innerWidth * 1})
.from('.text2', {x: innerWidth * -1})
.from('.text3', {x: innerWidth * 1})
.from('.logo', {
y: innerHeight * 1,
rotate: 360
}) gsap.timeline({
scrollTrigger: {
trigger: '.box2',
start: 'center center',
end: 'bottom top',
// markers: true,
scrub: true,
pin: true,
}
})
.from('.box2', {opacity: 0})
.from('.text4', {y: innerHeight * 1})
.from('.text5', {y: innerHeight * 1})
.from('.text6', {y: innerHeight * 1})

使用了 gsap 库, 能够添加动画效果

1.3 css 代码片段

基础设置

*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
overflow-x: hidden;
}
  • 注意, 这里设置了所有的 box-sizing 为 border-box, css3 特性

第一页设置

section{
position: relative;
width: 100%;
height: 100vh;
background: #000;
display: flex;
justify-content: center;
align-items: center;
}
section h2{
font-size: 6em;
color: #fff;
font-weight: 500;
}

第二页设置

.box{
position: relative;
width: 100%;
min-height: 100vh;
padding: 100px;
}
.box h2{
font-size: 3em;
}
.box .logo{
max-width: 400px;
}

第三页设置

.box2{
position: relative;
width: 100%;
min-height: 100vh;
padding: 100px;
background: #000;
}
.box2 h2{
font-size: 3em;
color: #fff;
}

2. 源码

2.1 html 源码

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="2021_1_13.css">
</head>
<body>
<section>
<h2>开 始 滑 动</h2>
</section>
<div class="box">
<h2 class="text1">来看看 滑动效果呗! </h2>
<h2 class="text2">我是向左</h2>
<h2 class="text3">我是向右 (#^.^#)</h2>
<img src="logo.jpg" class="logo">
</div>
<div class="box2">
<h2 class="text4">来看看滑动效果呗! </h2>
<h2 class="text5">代码在最后哦</h2>
<h2 class="text6">滑动效果是啥? </h2>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.6.0/gsap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.6.0/ScrollTrigger.min.js"></script> <script>
gsap.timeline({
scrollTrigger: {
trigger: '.box',
start: 'center center',
end: 'bottom top',
// markers: true,
scrub: true,
pin: true,
}
})
.from('.text1', {x: innerWidth * 1})
.from('.text2', {x: innerWidth * -1})
.from('.text3', {x: innerWidth * 1})
.from('.logo', {
y: innerHeight * 1,
rotate: 360
}) gsap.timeline({
scrollTrigger: {
trigger: '.box2',
start: 'center center',
end: 'bottom top',
// markers: true,
scrub: true,
pin: true,
}
})
.from('.box2', {opacity: 0})
.from('.text4', {y: innerHeight * 1})
.from('.text5', {y: innerHeight * 1})
.from('.text6', {y: innerHeight * 1}) </script>
</body>
</html>

2.2 css 源码

*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
overflow-x: hidden;
}
section{
position: relative;
width: 100%;
height: 100vh;
background: #000;
display: flex;
justify-content: center;
align-items: center;
}
section h2{
font-size: 6em;
color: #fff;
font-weight: 500;
}
.box{
position: relative;
width: 100%;
min-height: 100vh;
padding: 100px;
}
.box h2{
font-size: 3em;
}
.box .logo{
max-width: 400px;
}
.box2{
position: relative;
width: 100%;
min-height: 100vh;
padding: 100px;
background: #000;
}
.box2 h2{
font-size: 3em;
color: #fff;
}

这里使用到的 gsap 是很好的一个动画库, 值得我们学习.

每日CSS_滚动页面动画效果的更多相关文章

  1. 每日CSS_霓虹灯按钮悬停效果

    每日CSS_霓虹灯按钮悬停效果 2020_12_20 1. 代码解析 1.1 html 代码片段解析 <a href="#"> <span></spa ...

  2. [Android实例] app引导页(背景图片切换加各个页面动画效果)(申明:来源于网络)

    [Android实例] app引导页(背景图片切换加各个页面动画效果)(申明:来源于网络) 地址: http://www.eoeandroid.com/thread-918356-1-1.html h ...

  3. waypoint+animate元素滚动监听触发插件实现页面动画效果

    最近在做一个官网类型滚动加载动画,使用到waypoint监听事件插件和animate动画样式,两者结合完美实现向下滚动加载动画,但是没有做向上滚动撤消动画,留待以后有空研究 首先来介绍下jquery. ...

  4. wow.js让css3动画变动更有趣(滚动页面动画模拟懒加载特效)

    CSS3的出现给网站页面增加了活力,网站增色不少,有这么小小的一款插件就能做出很多动画效果. 最重要的是它:简单易用.轻量级.无需 jQuery......他就是wow.js 地址:https://d ...

  5. app引导页(背景图片切换加各个页面动画效果)

    前言:不知不觉中又加班到了10点半,整个启动页面做了一天多的时间,一共有三个页面,每个页面都有动画效果,动画效果调试起来麻烦,既要跟ios统一,又要匹配各种不同的手机,然后产品经理还有可能在中途改需求 ...

  6. 基于html5和css3响应式全屏滚动页面切换效果

    分享一款全屏响应式的HTML5和CSS3页面切换效果.这个页面布局效果对于那些页面要求固定100%高度和宽度的网站和APP来说是十分有用的.效果图如下: 在线预览   源码下载 HTML wrappe ...

  7. 前端实现app引导页面动画效果

    插件描述:jQuery引导插件TourTip 交互式可视化指南网页上的元素.使用方法 步骤1: 将以下标记添加到您的文档的<head> 你还需要复制旁边插件的css文件夹和下载的IMG文件 ...

  8. vue中,模拟锚点定位,实现滚动动画效果

    平时我们利用锚点进行页面内的快速瞬移,画面跳转生硬,观感很差. 在VUE中,如何快速的实现锚点效果,并且还让它拥有滚动的动画效果呢. 其实两行代码就能解决问题 1 <a @click=" ...

  9. 使用 SVG 来实现波浪 (wave) 动画效果

    如下图所示的波浪动画效果,实现方法有很多,比如CSS或者是js等方法都可以实现.不过,要是使用SVG来实现的,我觉得比其它两种方法都要简单.这篇文章就来讲讲使用SVG来实现类似这样的波浪动画效果是多么 ...

随机推荐

  1. STL-Vector容量问题:

    1.clear,erase ,pop_back() 函数只删除对象,并没有释放vec中的内存,若对象是指针还需要delete:2.在erase,clear,pop_back()删除对象的后,size改 ...

  2. 题解-CF436E Cardboard Box

    题面 CF436E Cardboard Box \(n\) 个关卡,对每个关卡可以花 \(a_i\) 时间得到 \(1\) 颗星,或花 \(b_i\) 时间得到 \(2\) 颗星,或不玩.问获得 \( ...

  3. 深入理解Java虚拟机(九)——后端编译与优化

    即时编译器 Java程序最初都是通过解释器进行执行,当发现某个方法或者代码块被运行得非常频繁,这些代码就被认为是热点代码,为了提高这些代码得运行效率,虚拟机会把热点代码编译成本地机器码,并进行优化,运 ...

  4. tensorflow学习笔记——DenseNet

    完整代码及其数据,请移步小编的GitHub地址 传送门:请点击我 如果点击有误:https://github.com/LeBron-Jian/DeepLearningNote 这里结合网络的资料和De ...

  5. Java中instanceof注意的地方

    instanceof只能用于对象的判断,不能用于基本类型的判断,以下代码会编译不通过 'A' instanceof Character instanceof特有的规则:若左操作数是null,结果就直接 ...

  6. Kafka Connect使用入门-Mysql数据导入到ElasticSearch

    1.Kafka Connect Connect是Kafka的一部分,它为在Kafka和外部存储系统之间移动数据提供了一种可靠且伸缩的方式,它为连接器插件提供了一组API和一个运行时-Connect负责 ...

  7. python 字典常用操作

    字典键是唯一的,但值则不是 一个简单的字典 dict = {"guo":"1106","tang":"0809",&qu ...

  8. 死磕以太坊源码分析之Ethash共识算法

    死磕以太坊源码分析之Ethash共识算法 代码分支:https://github.com/ethereum/go-ethereum/tree/v1.9.9 引言 目前以太坊中有两个共识算法的实现:cl ...

  9. Centos7路由设置

    再添加路由时,很多时候都是采用命令行用route添加的.但是在机器重启后.就失效了.这里也是参考了几位博主的经验 作出以下记载 一:路由表常用设置 1.route命令路由表常用设置: //添加到主机的 ...

  10. jfinal项目报java.lang.ClassNotFoundException: com.jfinal.core.JFinalFilter

    在eclipse中启动jfinal项目时,项目报错如下:首先:右击项目–>Build Path–>Source查看Default output folder如果是目录/WEB-INF/cl ...