TweenMax page-hopper
2016-03-21 21:52
465 查看
这个好看动画归功于TweenMax,line的x1跟x2一样,stroke-linecap="round",就出现圆点,然后动态改变x1和x2来实现移动 var tl = new TimelineMax();
tl.to('#joinLine', 0.3, {
attr:{
x1:target.getAttribute('cx')
},
strokeWidth:0,
}).to('#joinLine', 1, {
attr:{
x2:target.getAttribute('cx')
},
ease:Elastic.easeOut.config(1, 0.76)
}, '+=0')
.to('#joinLine', 2, {
strokeWidth:size,
ease:Elastic.easeOut.config(1, 0.8)
}, '-=1')
tl.timeScale(2)html代码
<body>
<div class="container">
<svg width="900px" height="900px" viewBox="0 0 800 600">
<defs>
<mask id="radioMask"></mask>
</defs>
<g id="mainGroup">
<g id="circleGroup" fill="transparent" stroke-width="4" stroke-miterlimit="10" stroke="#fff">
<circle cx="260" cy="300" r="23" />
<circle cx="330" cy="300" r="23" />
<circle cx="400" cy="300" r="23" />
<circle cx="470" cy="300" r="23" />
<circle cx="540" cy="300" r="23" />
</g>
<line id="joinLine" fill="none" stroke-width="20" stroke-linecap="round" stroke-miterlimit="10" x1="260" y1="300" x2="260" y2="300"/>
</g>
</svg>
</div>
<script src='http://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.2/TweenMax.min.js'></script>
<script src="index.js"></script>
</body>css代码
body {
background-color:#488BDA;
overflow: hidden;
}
body,
html {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
.container{
position:absolute;
max-width:100%;
}
svg{
max-width:100%;
visibility:hidden;
}
#circleGroup, #joinLine{
stroke:#fff;
}
circle{
cursor:pointer;
}js代码
var xmlns = "http://www.w3.org/2000/svg",
xlinkns = "http://www.w3.org/1999/xlink",
select = function(s) {
return document.querySelector(s);
},
selectAll = function(s) {
return document.querySelectorAll(s);
},
container = select('.container'),
size = 20
//center the container cos it's pretty an' that
TweenMax.set(container, {
position: 'absolute',
top: '50%',
left: '50%',
xPercent: -50,
yPercent: -50
})
TweenMax.set('svg', {
visibility: 'visible'
})
select('#joinLine').setAttribute('stroke-width', size);
var maskSource = select('#circleGroup').cloneNode(true);
maskSource.id = '';
maskSource.setAttribute('fill', '#FFF');
maskSource.setAttribute('stroke', '#777777');
maskSource.setAttribute('stroke-width', 5);
select('#radioMask').appendChild(maskSource);
select('#mainGroup').setAttribute('mask', 'url(#radioMask)')
document.body.onclick = function(e){
var target = e.target;
if(target.tagName == 'circle'){
var id = target.id;
var tl = new TimelineMax();
tl.to('#joinLine', 0.3, {
attr:{
x1:target.getAttribute('cx')
},
strokeWidth:0,
}).to('#joinLine', 1, {
attr:{
x2:target.getAttribute('cx')
},
ease:Elastic.easeOut.config(1, 0.76)
}, '+=0')
.to('#joinLine', 2, {
strokeWidth:size,
ease:Elastic.easeOut.config(1, 0.8)
}, '-=1')
tl.timeScale(2)
}
}
//automate the first one
document.body.onclick({target:selectAll('circle')[2]})
相关文章推荐
- Gifski:一个跨平台的高质量 GIF 编码器
- 模仿动画的放大缩小容器
- jQuery 1.9.1源码分析系列(十五)动画处理之缓动动画核心Tween
- Android实现定制返回按钮动画效果的方法
- Android中ViewFlipper的使用及设置动画效果实例详解
- jQuery实现美观的多级动画效果菜单代码
- php判断GIF图片是否为动画的方法
- jQuery实现动画效果circle实例
- HTML5游戏引擎LTweenLite实现的超帅动画效果(附demo源码下载)
- 浅析JavaScript动画
- js排序动画模拟-插入排序
- javascript+HTML5的Canvas实现Lab单车动画效果
- 基于javascript实现漂亮的页面过渡动画效果附源码下载
- js实现按钮颜色渐变动画效果
- 超赞的jQuery图片滑块动画特效代码汇总
- jQuery实现连续动画效果实例分析
- jQuery实现的给图片点赞+1动画效果(附在线演示及demo源码下载)
- jQuery实现带有洗牌效果的动画分页实例
- jQuery动画效果相关方法实例分析
- jquery实现先淡出再折叠收起的动画效果