TweenMax page-hopper

这个好看动画归功于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]})




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值