TweenMax学习总结(二)
页面布局
<body>
<div id="div1"></div>
</body>
<style>
html,body{
margin: 0;
padding: 0;
}
#div1{
width: 100px;
height: 100px;
background-color: #8D121A;
position: absolute;
left: 0;
top: 100px;
}
</style>
add()方法
add()方法用来添加状态,其参数为字符串或一个函数
add(“字符串”)
<script>
$(function(){
var t =new TimelineMax();
t.to("#div1",2,{left:300});
t.add("state1");
t.to("#div1",2,{width:300});
t.add("state2");
t.to("#div1",2,{height:300});
t.add("state3");
});
</script>
- add(函数)
<script>
$(function(){
var t =new TimelineMax();
t.to("#div1",2,{left:300});
t.add(function(){
$("#div1").css("background","blue");
});
t.to("#div1",2,{width:300});
t.to("#div1",2,{height:300});
});
</script>
tweenTo()方法
tweenTo()方法用来完成指定的动画,其包含有过渡的过程,参数为指定时间的Number或状态的字符串
tweenTo(时间)
<script>
$(function(){
var t =new TimelineMax();
t.to("#div1",2,{left:300});
t.to("#div1",2,{width:300});
t.to("#div1",2,{height:300});
t.tweenTo(3);
});
</script>
- tweenTo(“字符串”)
<script>
$(function(){
var t =new TimelineMax();
t.to("#div1",2,{left:300});
t.add("state1"); //添加状态
t.to("#div1",2,{width:300});
t.add("state2");
t.to("#div1",2,{height:300});
t.add("state3");
t.tweenTo("state2");
});
</script>
add()与tweenTo()综合应用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
html,body{
margin: 0;
padding: 0;
}
#div1{
width: 100px;
height: 100px;
background-color: #8D121A;
position: absolute;
left: 0;
top: 100px;
}
</style>
</head>
<body>
<div id="div1"></div>
<script src="js/jquery-2.1.4.min.js"></script>
<script src="js/TweenMax.js"></script>
<script>
$(function () {
var t = new TimelineMax();
t.to("#div1",2,{left:300});
t.add("state1");//添加状态
t.add(function(){
$("#div1").css("background","blue");
});
t.to("#div1",2,{width:300});
t.add("state2");
t.to("#div1",2,{height:300});
t.add("state3");
t.stop();
t.tweenTo("state3");
t.tweenTo(2);
});
</script>
</body>
</html>