html5 svg点击按钮碎片化消失过渡动画特效

来源:https://www.sucaihuo.com/js/3724.html 2018-06-03 11:29浏览(1633) 收藏

html5 svg点击按钮碎片化消失过渡动画特效,共有3种过渡动画效果。
html5 svg点击按钮碎片化消失过渡动画特效
分类:html/css > 按钮 难易:初级
查看演示 下载资源 下载积分: 10 积分

js代码

<script>
function anim1(path) {
  path.style.transitionDelay = `${Math.random() * 200}ms`;
  path.style.transformOrigin = `${Math.random() * 50 + 25}% 0%`;
  path.style.transform = `scale(0) rotate(${Math.random() * 100 - 50}deg)`;
  path.style.fill = '#777';
  path.style.stroke = '#555';
}

function reset1(path) {
  path.style.transitionDelay = 0;
  path.style.transformOrigin = `50%`;
  path.style.transform = `scale(1) rotate(0)`;
  path.style.fill = '#273439';
  path.style.stroke = '#273439';
}

function anim2(path, i) {
  path.style.transitionDuration = '1000ms';
  path.style.transitionDelay = `${i * 50}ms`;
  path.style.transformOrigin = `50%`;
  path.style.transform = `scale(0) translateX(${100 + i * 20}px)`;
  path.style.fill = '#777';
  path.style.stroke = '#555';
}


function reset2(path) {
  path.style.transitionDuration = 0;
  path.style.transitionDelay = 0;
  path.style.transformOrigin = `50%`;
  path.style.transform = `scale(1) translateX(0)`;
  path.style.fill = '#273439';
  path.style.stroke = '#273439';
}

const anims = [anim1, anim2, anim1],
      resets = [reset1, reset2, reset1],
      buttons = Array.from(document.querySelectorAll('.button')),
      refresh = document.querySelector('.refresh')
buttons.forEach((button, i) => {
  const submit = button.querySelector('.submit');
  let paths = button.querySelectorAll('path')
  submit.addEventListener('click', () => {
    paths.forEach((path, j) => {
      anims[i](path, j);
    });
    submit.style.backgroundColor = 'transparent';
    submit.style.opacity = '0';
  })
})

refresh.addEventListener('click', (e) => {
  buttons.forEach((button, i) => {
    const submit = button.querySelector('.submit');
    let paths = button.querySelectorAll('path')
    paths.forEach((path, j) => {
      resets[i](path, j);
    });
    setTimeout(() => {
      submit.style.backgroundColor = '#273439';
      submit.style.opacity = '1';
    }, 500)
  })
})</script>
评论0
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791

1 2