<head>
<meta charset=”UTF-8″>
<title>
web前端开发界面实例:动画框架</title>
</head>
<style>
body {
background-color: black;
margin: 0;
padding: 0;
font-family: Signika Negative, sans-serif;
font-weight: 300;
}
body {
height: 100%;
}
#demo {
display: table;
width: 100%;
height: 100%;
}
#bg {
position: relative;
display: table-cell;
height: 100%;
overflow: hidden;
text-align: center;
vertical-align: middle;
}
#bg p {
position: absolute;
color: #777;
top: 0px;
padding: 0px 20px;
text-align: left;
z-index: -1000;
}
#box {
color: black;
font-size: 24px;
padding: 10px 16px;
border: 2px solid black;
background: #9af600;
background: -webkit-linear-gradient(top, rgba(184, 225, 252, 1) 0%, rgba(169, 210, 243, 1) 10%, rgba(144, 186, 228, 1) 25%, rgba(144, 188, 234, 1) 37%, rgba(144, 191, 240, 1) 50%, rgba(107, 168, 229, 1) 51%, rgba(162, 218, 245, 1) 83%, rgba(189, 243, 253, 1) 100%);
display: inline-block;
border-radius: 10px;
}
#controls {
position: absolute;
color: #999;
width: 100%;
bottom: 20px;
text-align: center;
}
button {
margin: 2px;
padding: 4px 6px;
}
</style>
<body>
<div id=”demo”>
<div id=”bg”>
<p>tweenlite,是webgame开发人员比较常用的一个缓动库。 先简单介绍它的优点吧。 1.高效,性能不会差。 2.体积小,用到项目中,你的文件大小增加了3-4k。 3.容易使用,常用的函数就那么几个
</p>
<div id=”box”>TweenMax.
js 应用</div>
<div id=”controls”>
<button id=”rotationX”>X轴旋转</button>
<button id=”rotationY”>Y轴旋转</button>
<button id=”rotation”>转圈</button>
<button id=”wander”>漫游</button>
</div>
</div>
</div>
</body>
<script src=”https://cdnjs.cloudflare.com/ajax/libs/
jquery/2.1.3/
jquery.min.js”></script>
<script src=”https://cdnjs.cloudflare.com/ajax/libs/gsap/1.11.2/TweenMax.min.js”></script>
<script>
var $box = $(“#box”),
$container = $(“#bg”),
rotation = 0,
rotationX = 0,
rotationY = 0,
wanderTween, ignoreRollovers;
//设置3D容器视角
TweenLite.set($container, { perspective: 500 });
//取消Z轴,使旋转更加有趣。
TweenLite.set($box, { transformOrigin: “center center -150px” });
//使用scaleX和scaleY微微颤动起来
TweenMax.to($box, 1.2, { scaleX: 0.8, scaleY: 0.8, force3D: true, yoyo: true, repeat: -1, ease: Power1.easeInOut });
//翻转、旋转盒子但要避免过度旋转,我们会降低滚动在第一秒的动画。
$box.hover(function () {
if (!ignoreRollovers) {
rotation += 360;
ignoreRollovers = true;
TweenLite.to($box, 2, { rotation: rotation, ease: Elastic.easeOut });
TweenLite.delayedCall(1, function () {
ignoreRollovers = false;
});
}
}, function () { });
$(“#rotation”).click(function () {
rotation += 360;
TweenLite.to($box, 2, { rotation: rotation, ease: Elastic.easeOut });
});
$(“#rotationX”).click(function () {
rotationX += 360;
TweenLite.to($box, 2, { rotationX: rotationX, ease: Power2.easeOut });
});
$(“#rotationY”).click(function () {
rotationY += 360;
TweenLite.to($box, 2, { rotationY: rotationY, ease: Power1.easeInOut });
});
$(“#wander”).click(function () {
if (wanderTween) {
wanderTween.kill();
wanderTween = null;
TweenLite.to($box, 0.5, { x: 0, y: 0 });
} else {
wander();
}
});
//随机选择一个在屏幕上和动画,然后做一遍,又一遍。
function wander() {
var x = (($container.width() – $box.width()) / 2) * (Math.random() * 1.8 – 0.9),
y = (($container.height() – $box.height()) / 2) * (Math.random() * 1.4 – 0.7);
wanderTween = TweenLite.to($box, 2.5, { x: x, y: y, ease: Power1.easeInOut, onComplete: wander });
}
</script>
评论前必须登录!
注册