效果
相关插件
easing.js 动画增强插件
fullpage.js 全屏滚动插件
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<!-- 1. 引入文件 -->
<link rel="stylesheet" href="./css/jquery.fullpage.min.css">
<link rel="stylesheet" href="./css/index.css">
<script src="./js/jquery-1.8.3.min.js"></script>
<!-- jquery动画增强插件,扩展了更多种jqeury的动画效果 -->
<script src="./js/jquery.easing.1.3.js"></script>
<!-- 页面全屏滚动插件 -->
<script src="./js/jquery.fullpage.min.js"></script>
<script src="./js/index.js"></script>
</head>
<body>
<!-- 实现页面的主体结构 -->
<div id="animate">
<!-- 第一屏 -->
<div class="section section1">
<img src="./images/01/ball.png" alt="" class="ball">
<img src="./images/01/sofa.png" alt="" class="sofa">
<img src="./images/01/products.png" alt="" class="products">
</div>
<!-- 第二屏 -->
<div class="section section2">
<img src="./images/02/search01.png" alt="" class="search01">
<img src="./images/02/search02.png" alt="" class="search02">
<!-- 测试用的 -->
<!-- <img src="./images/02/search02.png" alt="" class="search03"> -->
<!-- <img src="./images/02/sofas.png" alt="" class="sofas"> -->
<!-- 用来给沙发做定位参考的div -->
<div class="computer">
<img src="./images/02/sofas.png" alt="" class="sofas">
</div>
</div>
<!-- 第三屏 -->
<div class="section section3">
<img src="./images/03/sofa.png" alt="" class="sofa">
<div class="color01"></div>
<div class="add01"></div>
</div>
<!-- 第四屏 -->
<div class="section section4">
<div class="carbox">
<img src="./images/04/sofa.png" class="sofa" alt="">
<img src="./images/04/car.png" alt="" class="car">
</div>
<div class="keyboard">
<img src="./images/04/address.png" alt="" class="address">
</div>
<img src="./images/04/words02.png" alt="" class="words">
<img src="./images/04/cloud.png" alt="" class="cloud">
</div>
<!-- 第五屏 -->
<div class="section section5">
<img src="./images/05/bill.png" alt="" class="bill">
<img src="./images/05/card.png" alt="" class="card">
<div class="mouse"></div>
<img src="./images/05/hand.png" alt="" class="hand">
<img src="./images/05/words.png" alt="" class="words">
</div>
<div class="section section6">
<!-- 街道 -->
<div class="street">
<!-- 门 -->
<img src="./images/06/door.png" class="door" alt="">
<!-- 女孩 -->
<img src="./images/06/girl.png" class="girl" alt="">
</div>
<!-- 天上的沙发盒子 -->
<div class="sofabox">
<!-- 盒子里的沙发 -->
<img src="./images/04/sofa.png" alt="" class="sofa">
<!-- 小盒子 -->
<img src="./images/06/box.png" alt="" class="box">
</div>
<!-- 车和送货的男孩 -->
<div class="carbox">
<!-- 男孩子的图片 -->
<img src="./images/06/man.png" alt="" class="man">
<!-- 小车图片 -->
<img src="./images/06/car.png" alt="" class="car">
</div>
<!-- 天上的白云 -->
<img src="./images/04/cloud.png" class="cloud" alt="">
</div>
<!-- 第七屏 -->
<div class="section section7">
<div class="stars"></div>
<img src="./images/07/good.png" alt="" class="good">
</div>
<div class="section section8 active">
<div class="begin"></div>
<img src="./images/08/again.png" alt="" class="again">
<img src="./images/08/hand.png" alt="" class="hand">
</div>
</div>
</body>
</html>
css
/* 第一屏 */
.section1 {
background: url("../images/01/bg.png") no-repeat center bottom;
}
.section1 .sofa {
position: absolute;
left: 50%;
margin-left: -200px;
bottom: 320px;
animation: sofa 1s infinite;
}
.section1 .products {
position: absolute;
left: 50%;
margin-left: -400px;
bottom: 200px;
}
.section1 .ball {
position: absolute;
right: 50px;
top: 50px;
animation: ball 3s infinite;
}
@keyframes sofa {
50% {
transform: translate(0px, -20px);
}
}
@keyframes ball {
50% {
transform: translate(0px, -30px);
}
}
/* 第二屏 */
.section2 {
background: url("../images/02/bg.png") no-repeat center bottom;
}
.section2 .search01 {
position: absolute;
left: 50%;
margin-left: 400px;
bottom: 300px;
}
.section2 .search02 {
position: absolute;
left: 50%;
margin-left: -111px;
bottom: 300px;
display: none;
}
.section2 .search03 {
height: 30px;
position: absolute;
left: 50%;
margin-left: 130px;
bottom: 450px;
}
.section2 .computer {
width: 576px;
height: 250px;
position: absolute;
left: 50%;
margin-left: -290px;
bottom: 195px;
}
.section2 .sofas {
position: absolute;
height: 0px;
right: 65px;
bottom: 20px;
}
/* 第三屏的动画及布局 */
.section3 {
background: url("../images/03/bg.png") no-repeat center bottom;
}
.section3 .sofa {
position: absolute;
left: 50%;
margin-left: -240px;
bottom: 250px;
}
.section3 .color01 {
background: url("../images/03/color01.gif") no-repeat;
width: 296px;
height: 131px;
position: absolute;
left: 50%;
margin-left: 40px;
bottom: 175px;
}
.section3.animation .color01 {
transition: all 0.5s;
background: url("../images/03/color02.gif") no-repeat;
}
.section3 .add01 {
background: url("../images/03/add01.gif") no-repeat;
width: 218px;
height: 58px;
position: absolute;
left: 50%;
margin-left: 40px;
bottom: 100px;
}
.section3.animation .add01 {
transition: all 0.5s 0.5s;
background: url("../images/03/add02.gif") no-repeat;
}
/* 第四屏 */
.section4 {
background: url("../images/04/bg.png") no-repeat center bottom;
}
.section4 .carbox {
width: 407px;
height: 346px;
position: absolute;
bottom: 50px;
left: 50%;
margin-left: -340px;
}
.section4 .car {
position: absolute;
}
.section4 .sofa {
position: absolute;
left: 165px;
top: -45px;
}
.section4 .keyboard {
width: 283px;
height: 270px;
background: url("../images/04/keyboard.png") no-repeat;
position: absolute;
left: 50%;
bottom: 140px;
margin-left: -235px;
display: none;
}
.section4 .address {
position: absolute;
left: 50%;
margin-left: -86px;
top: 50px;
}
.section4 .words {
position: absolute;
left: 50%;
margin-left: -300px;
bottom: 450px;
}
.section4 .cloud {
position: absolute;
left: 50%;
margin-left: -300px;
bottom: 500px;
animation: cloud 20s linear infinite;
}
@keyframes cloud {
50% {
transform: translate(-1000px, 0px);
}
}
/* 第五屏 */
.section5 {
background: url("../images/05/bg.png") no-repeat bottom center;
overflow: hidden;
perspective: 500px;
}
.section5 .card {
position: absolute;
left:50%;
margin-left: -390px;
bottom: 170px;
}
.section5 .bill {
position: absolute;
left:50%;
margin-left: -250px;
bottom: 260px;
}
.section5 .mouse {
width: 205px;
height: 819px;
position: absolute;
left:50%;
margin-left: 200px;
bottom: 220px;
background: url("../images/05/mouse01.png") no-repeat;
}
.section5 .hand {
position: absolute;
left:50%;
margin-left: 180px;
bottom: -100px;
}
.section5 .words {
position: absolute;
left: 50%;
margin-left: -160px;
bottom: 530px;
transform-style: preserve-3d;
transform: scale(0) rotateY(-360deg);
}
.section5.animation .hand {
transition: all 2s;
bottom: -30px;
}
.section5.animation .mouse {
transition: all 0.5s 2s;
background: url("../images/05/mouse02.png") no-repeat;
}
.section5.animation .bill {
transition: all 0.5s 2.5s;
bottom: 390px;
}
.section5.animation .words {
transition: all 1s 3s;
transform: scale(1.2) rotateY(0deg);
}
/* 第六屏 */
/* 街道 */
.section6 .street {
width: 5000px;
height: 600px;
background: url("../images/06/bg.png") repeat-x;
position: absolute;
left: -200px;
bottom: 0;
/* border: 3px solid #000; */
}
/* 门 */
.section6 .door {
position: absolute;
left: 2110px;
bottom: 116px;
/* 一开始是关着门的 */
display: none;
}
/* 女孩子 */
.section6 .girl {
position: absolute;
left: 2135px;
bottom: 105px;
height: 110px;
/* 一开始女孩子是在室内的 */
display: none;
}
/* 装小车的大盒子 */
.section6 .carbox {
width: 221px;
height: 122px;
position: absolute;
left: 505px;
bottom: 85px;
}
/* 男孩子 */
.section6 .man {
position: absolute;
height: 120px;
right: 0;
bottom: 20px;
height: 30px;
}
/* 小车 */
.section6 .car {
position: absolute;
}
/* 装沙发的大盒子 */
.section6 .sofabox {
width: 123px;
height: 85px;
position: absolute;
left: 520px;
bottom: 400px;
/* background-color: yellowgreen; */
}
/* 沙发 */
.section6 .sofa {
position: absolute;
height: 80px;
left: 20px;
top: -20px;
}
/* 小盒子 */
.section6 .box {
position: absolute;
}
/* 白云 */
.section6 .cloud {
position: absolute;
left: 50%;
margin-left: -300px;
bottom: 500px;
animation: cloud 20s linear infinite;
}
/* 第七屏 */
.section7 {
background: url("../images/07/bg.png") no-repeat bottom center;
}
.section7 .stars {
position: absolute;
left: 50%;
margin-left: -300px;
bottom: 442px;
/* width: 105px; */
width: 0;
height: 17px;
background: url("../images/07/stars3.png") no-repeat;
}
.section7.animation .stars {
transition: all 2s steps(5);
width: 105px;
}
.section7 .good {
position: absolute;
left: 50%;
margin-left: -290px;
bottom: 380px;
opacity: 0;
}
.section7.animation .good {
transition: all 0.5s 2s;
opacity: 1;
}
/* 第八屏 */
.section8 {
background: url("../images/08/bg.png");
}
.section8 .begin {
width: 389px;
height: 160px;
position: absolute;
bottom: 380px;
left: 50%;
margin-left: -195px;
background: url("../images/08/begin.png") no-repeat;
}
.section8 .begin:hover {
background: url("../images/08/begin.gif") no-repeat;
}
.section8 .again {
position: absolute;
right: 100px;
bottom: 100px;
}
.section8 .hand {
position: absolute;
bottom: 0;
left: 0;
/* 不让该元素响应事件, 事件会默认向下传 */
pointer-events: none;
/* left: 50%;
margin-left: -85px; */
}
js
$(function() {
$("#animate").fullpage({
navigation: true, // 显示页数导航
sectionsColor: ["#f9dd67", "#84a2d4", "#ef674d", "#ffeedd", "#cf4759", "#85d9ed", "#6faa85", "#84d9ed"],
//进入到某一屏时调用
afterLoad: function(a, index) {
//每一次离开当前屏(进入下一屏时), 把所有的js动画先清除。 jquery的动画的本质,其实是给动画元素添加了style的属性, 所以清除动画就是把style的属性干掉
$(".section>div img, .section>div div").attr("style", "");
//如果上一屏的动画还没有执行完,就把该动画停掉
$(".section>div img, .section>div div").stop();
//移动所有的css动画, 同时给当前屏添加css动画
$(".section").removeClass("animation").eq(index-1).addClass("animation");
//给第二屏添加动画
if (index == 2) {
//让左侧的搜索框移动到中间
$(".section2 .search01").animate({marginLeft:-111}, 1000, "easeOutBack", function() {
//左侧的搜索框移动到中间就隐藏,中间的带字的搜索框显示出来,停顿0.5秒之后, 移动到右上角
$(this).hide();
$(".section2 .search02").show().delay(500).animate({height: 30, marginLeft: 130, bottom: 450}, 1000);
//沙发变大
$(".section2 .sofas").delay(500).animate({height: 218}, 1000);
});
}
//给第四屏添加动画
if (index == 4) {
$(".section4 .carbox").animate({marginLeft: 1000}, 2000, "easeInElastic", function() {
//delay方法可以对animate方法生效,但是不能对show来效
$(".section4 .keyboard").fadeIn(500);
})
}
//给第六屏添加动画
if (index == 6) {
//天上掉下沙发来
$(".section6 .sofabox").animate({bottom: 100}, 1000, function() {
//街道开始往左移动, 模拟开车效果
$(".section6 .street").animate({left: -1200}, 7000, function() {
//男孩子下车, 变大
$(".section6 .man").animate({height: 120}, 500, function() {
//男孩子向右移动一段距离
$(".section6 .man").animate({right: -150}, 1000, function() {
//开门,让门这个元素显示出来
$(".section6 .door").show();
//延迟500ms执行
setTimeout(function() {
//让女孩这个元素显示出来
$(".section6 .girl").show();
}, 500);
});
});
});
})
}
//第八屏的js效果
if (index == 8) {
//拿到窗口的高度
var screenheight = $(window).height();
console.log(screenheight);
//监听鼠标的移动事件
$(".section8").mousemove(function(target) {
//console.log(target.pageY);
//拿到鼠标所在的x, y的坐标
var x = target.pageX;
var y = target.pageY;
//定位中的left的值
var left = x - 65;
var bottom = (screenheight-y) - 449;
if (bottom >=0) bottom = 0;
$(".section8 .hand").css({left: left, bottom: bottom});
});
$(".section8 .again").click(function() {
//fullpage插件调方法
$.fn.fullpage.moveTo(1);
});
}
}
});
});
以下是实现购物车的要点及大致思路
1. fullPage 插件(先查看文档,了解其用法)
2. 中线对齐
* left: 50%
* margin-left: -100px
* position: absolute
3. 第一屏,简单的元素布局, 加css弹跳动画
4. 第二屏, jquery动画, easing.js(jquery的动画增强插件)
* $("dom").animate({left: 100}, 1000, "easeOutBack", function() {})
* http://www.runoob.com/jqueryui/api-easings.html
* jquery的动画实现原理:
1. 给动画元素添加了 style的属性, 设置了动画的终值。
2. 如果我们要还原动画, 只需要把style属性的值清空掉
3. 如果我们要结束未完成的动画, dom.stop();
5. 第三屏
* css动画
* css改变元素的background属性(注意: 选择颜色和加入到购物车这两个元素要使用div而不是img)
* 添加删除动画的原理: 给section添加或删除animation
6. 第四屏
1. 小车的盒子的布局(中线对齐)
2. 小车抖动着前进的动画 "easeInElastic"
3. 在回调函数中,显示地址(keyboard的div)
4. 添加文字
5. 添加白云和动画