<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>圣诞主题</title>
<link rel='stylesheet' href='common.css' />
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
<script src="pageC.js"></script>
<script src="pageB.js"></script>
<script src="pageA.js"></script>
<script src="christmas.js"></script>
</head>
<body>
<section class="container">
<!-- 第一幅画面 -->
<section class="page-a bg-adaptive">
</section>
<!-- 第二幅画面 -->
<section class="page-b bg-adaptive">
</section>
<!-- 第三幅画面 -->
<section class="page-c bg-adaptive">
</section>
</section>
选择页面:
<select id="choose">
<option value="page-a" selected="">1</option>
<option value="page-b">2</option>
<option value="page-c">3</option>
</select>
<script type="text/javascript">
/**
* 自适应页面大小
* @param {[type]} doc [description]
* @param {[type]} win [description]
* @return {[type]} [description]
*/
var docEl = document.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function() {
//自适应设置容器高度
var container = document.querySelector(".container")
//原始比例
var proportion = 900 / 1440;
container.style.height = container.clientWidth * proportion + "px";
};
window.addEventListener(resizeEvt, recalc, false);
document.addEventListener('DOMContentLoaded', recalc, false);
</script>
</body>
</html>
/**
* 慕课网特制
* 圣诞主题效果
* @type {Object}
*/
/**
* 切换页面
* 模拟镜头效果
* @return {[type]} [description]
*/
function changePage(element,effect,callback){
element
.addClass(effect)
.one("animationend webkitAnimationEnd", function() {
callback && callback();
})
}
/**
* 中间调用
*/
var Christmas = function() {
//页面容器元素
var $pageA = $(".page-a");
var $pageB = $(".page-b");
var $pageC = $(".page-c");
//切换切换
$("#choose").on("change", function(e) {
//页面名称
var pageName = e.target.value;
switch (pageName) {
case "page-b":
//切换到页面B,然后捕获到切换后的通知
changePage($pageA, "effect-out", function() {
new pageB()
})
break;
case "page-c":
//切换到页面C,然后捕获到切换后的通知
changePage($pageC, "effect-in", function() {
new pageC()
})
break;
}
})
};
$(function() {
//圣诞主题效果,开始
Christmas()
})
function pageA (argument) {
alert("页面C")
}
function pageB (argument) {
alert("页面B")
}
function pageC (argument) {
alert("页面C")
}
*{
margin: 0;
padding: 0;
}
/*body{
width: 100%;
height: 100%;
}*/
.container {
width: 100%;
height: 100%;
position: relative;
overflow: hidden;
}
.bg-adaptive {
background-size: 100% 100%;
}
.container .page-a {
width : 100%;
height : 100%;
background-image: url("http://img1.sycdn.imooc.com//565d07770001790814410901.png");
position: absolute;
z-index: 5;
}
.container .page-b {
width : 100%;
height : 100%;
background-image: url("http://img1.sycdn.imooc.com//565d09fa000145a614410901.png");
position: absolute;
z-index: 4;
}
.page-c {
width : 100%;
height : 100%;
background-image: url("http://img1.sycdn.imooc.com//565d0b280001788014410901.png");
position: absolute;
z-index: 3;
}
/**
* 页面切换
* 镜头方法
*/
.effect-out{
-webkit-animation: effectOut 8s ease-in-out forwards;
-webkit-transform-origin:71% 72%;
-moz-animation: effectOut 8s ease-in-out forwards;
-moz-transform-origin:71% 72%;
}
@-webkit-keyframes effectOut{
0% { opacity:1; }
100% { -webkit-transform: scale(20); opacity:0; }
}
@-moz-keyframes effectOut{
0% { opacity:1; }
100% { -moz-transform: scale(20); opacity:0; }
}
.effect-in{
z-index: 15;
display: block;
opacity:0;
-webkit-transform: scale(8);
-webkit-animation: effectIn 5s ease-in-out forwards;
-webkit-transform-origin:58.5% 73.5%;
-moz-transform: scale(8);
-moz-animation: effectIn 5s ease-in-out forwards;
-moz-transform-origin:58.5% 73.5%;
}
@-webkit-keyframes effectIn{
100% { -webkit-transform: scale(1); opacity:1; }
}
@-moz-keyframes effectIn{
100% { -moz-transform: scale(1); opacity:1; }
}