注册 登录 充值会员 退出
联系客服 毕业设计 java源码 PHP源码
充值

html5杯子里萤火虫发光动画特效

作者/代码整理:  (源码已亲测,不会安装的可以向QQ1915635791要安装视频教程) 发布日期:2022-05-01
html5杯子里萤火虫发光动画特效
一款很好看的html5杯子里萤火虫发光动画特效,萤火虫关在杯子里跟随鼠标摇晃动画效果。


js代码

<script src="js/TweenMax.min.js"></script>
<script>
var numP = 50;

TweenMax.set("#content", {transformOrigin:"50% -45%"})
//TweenMax.fromTo("#particles", .7, {background:'rgb(16,17,24)'}, {background:'rgb(18,15,23)', repeat:-1, yoyo:true, ease:Elastic.easeInOut})

for (var i = 0; i<=numP; i++) {
  if (i==0){
    TweenMax.set("#p0", {scale:0})
    //loop(document.getElementById('p0'), 0);
  }
  else {
    var _p = document.getElementById('p0').cloneNode(false);
    _p.id = "p" + i;
    document.getElementById('particles').appendChild(_p);
    TweenMax.fromTo(_p, 13, {
              x:120+110*Math.random(),
              y:200+250*Math.random(),
              scale:3*Math.random()
            },{
              bezier:{ type:'thru', values:[
                {x:99+60*Math.random(), y:50+100*Math.random(), scale:.5+Math.random(), alpha:1},
                {x:40+80*Math.random(), y:200+160*Math.random(), scale:3-Math.random(), alpha:0.25},
                {x:60+60*Math.random(), y:390+50*Math.random(), scale:3*Math.random(), alpha:.7+.3*Math.random()}],
              },
              onComplete:loop,
              onCompleteParams:[_p],
              ease:Sine.easeInOut
    }).progress(i/numP)
  }
}

function loop(_p){
 var tl = new TimelineMax({yoyo:true, repeat:-1})
     //.to(_p, 3, {x:100+50*Math.random(), y:380+50*Math.random(), scale:1+2*Math.random(), ease:Linear.easeNone}, 0)
     .to(_p, 14, {
              ease:Sine.easeInOut,//Linear.easeNone,
              bezier:{ type:'thru', values:[
                {x:190+30*Math.random(), y:100+60*Math.random(), scale:3-Math.random()},
                {x:190+50*Math.random(), y:150+100*Math.random(), scale:.5+Math.random(), alpha:1},
                {x:190-60*Math.random(), y:200+160*Math.random(), scale:3-Math.random(), alpha:0.25},
                {x:200-70*Math.random(), y:390+50*Math.random(), scale:3*Math.random(), alpha:1}],
              }})
}

window.addEventListener('mousemove',function(e){
  TweenMax.to("#content", .5, {x:-400+800*(e.clientX/window.innerWidth), rotation:-25+50*(e.clientX/window.innerWidth)})
})</script>

关注公众号,免费赠送安装视频教程、环境和学习视频,后面会不断更新。