每日CSS_滚动页面动画效果
每日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_滚动页面动画效果的更多相关文章
- 每日CSS_霓虹灯按钮悬停效果
		
每日CSS_霓虹灯按钮悬停效果 2020_12_20 1. 代码解析 1.1 html 代码片段解析 <a href="#"> <span></spa ...
 - [Android实例] app引导页(背景图片切换加各个页面动画效果)(申明:来源于网络)
		
[Android实例] app引导页(背景图片切换加各个页面动画效果)(申明:来源于网络) 地址: http://www.eoeandroid.com/thread-918356-1-1.html h ...
 - waypoint+animate元素滚动监听触发插件实现页面动画效果
		
最近在做一个官网类型滚动加载动画,使用到waypoint监听事件插件和animate动画样式,两者结合完美实现向下滚动加载动画,但是没有做向上滚动撤消动画,留待以后有空研究 首先来介绍下jquery. ...
 - wow.js让css3动画变动更有趣(滚动页面动画模拟懒加载特效)
		
CSS3的出现给网站页面增加了活力,网站增色不少,有这么小小的一款插件就能做出很多动画效果. 最重要的是它:简单易用.轻量级.无需 jQuery......他就是wow.js 地址:https://d ...
 - app引导页(背景图片切换加各个页面动画效果)
		
前言:不知不觉中又加班到了10点半,整个启动页面做了一天多的时间,一共有三个页面,每个页面都有动画效果,动画效果调试起来麻烦,既要跟ios统一,又要匹配各种不同的手机,然后产品经理还有可能在中途改需求 ...
 - 基于html5和css3响应式全屏滚动页面切换效果
		
分享一款全屏响应式的HTML5和CSS3页面切换效果.这个页面布局效果对于那些页面要求固定100%高度和宽度的网站和APP来说是十分有用的.效果图如下: 在线预览 源码下载 HTML wrappe ...
 - 前端实现app引导页面动画效果
		
插件描述:jQuery引导插件TourTip 交互式可视化指南网页上的元素.使用方法 步骤1: 将以下标记添加到您的文档的<head> 你还需要复制旁边插件的css文件夹和下载的IMG文件 ...
 - vue中,模拟锚点定位,实现滚动动画效果
		
平时我们利用锚点进行页面内的快速瞬移,画面跳转生硬,观感很差. 在VUE中,如何快速的实现锚点效果,并且还让它拥有滚动的动画效果呢. 其实两行代码就能解决问题 1 <a @click=" ...
 - 使用 SVG 来实现波浪 (wave) 动画效果
		
如下图所示的波浪动画效果,实现方法有很多,比如CSS或者是js等方法都可以实现.不过,要是使用SVG来实现的,我觉得比其它两种方法都要简单.这篇文章就来讲讲使用SVG来实现类似这样的波浪动画效果是多么 ...
 
随机推荐
- Intellij IDEA新导入项目运行出现Error:(60, 47) java: -source 1.5 中不支持 diamond 运算符   (请使用 -source 7 或更高版本以启用 diamond 运算符)
			
后台窗口报错如下: 问题原因 项目jdk版本配置不正确. 解决方案 ①File ->Project Structure ② ③之后还要检查一下这里 Settings-->Build,Exe ...
 - 使用eslint将项目中的代码修改统一的缩进
			
背景 继承了组里师兄师姐写的项目的前端代码,但是是两个人写的,有两格缩进的,有四格缩进的,有字符串外用单引号的,有用双引号的. 于是搜索了一下,可以用eslint强制转化. eslint在github ...
 - 题解-FJOI2018 领导集团问题
			
题面 FJOI2018 领导集团问题 给一棵树 \(T(|T|=n)\),每个点有个权值 \(w_i\),从中选出一个子点集 \(P=\{x\in {\rm node}|x\in T\}\),使得 \ ...
 - 转载:c# 获取CPU温度(非WMI,直接读取硬件)
			
c#获取cpu温度 很早一个项目做远控,所以需要用到获取cpu温度,但是就是不知从何下手,无意中发现了Open Hardware Monitor,令我的项目成功完成 亲测20台清装xp sp2的机器, ...
 - C++ 虚函数表与多态 —— 多重继承的虚函数表 & 内存布局
			
多重继承的虚函数表会有两个虚表指针,分别指向两个虚函数表,如下代码中的 vptr_s_1.vptr_s_2,Son类继承自 Father 和 Mather 类,并且改写了 Father::func_1 ...
 - 20201128-2 【自动化办公】读写csv文件
			
Exercise 1 import csv # 设置员工发展基金确认表路径 source_path = './员工发展基金确认表.csv' # 设置存放拆分结果文件的文件夹路径 result_path ...
 - IntelliJ IDEA(十二) :IDEA常用配置
			
idea版本 2019.3.4 配置JDK File--> Project Structure... 修改项目 jdk和项目语言等级 修改jdk版本 File--> Ohter Setti ...
 - Kafka服务器后台启动
			
nohup bin/kafka-server-start.sh config/server.properties 1>/dev/null 2>&1 &
 - angular8
			
@Component 装饰器告诉Angular , AppComponent 类是一个组件,装饰器的属性用于配置该组件的应用方式. selectot 属性告诉Angular如何在HTML文档中应用该组 ...
 - Semaphore信号量深度解析
			
1. 使用指南 package com.multthread; import java.util.concurrent.ExecutorService; import java.util.concur ...