javascript - 切换后链接页面

标签 javascript html css gsap

我有一个动画切换按钮。动画完成后,我希望将用户重定向到另一个页面。此代码来自:https://codemyui.com/flipping-egg-toggle-switch/

我以前没有使用过开关,不确定是否有标准方法可以做到这一点。

谢谢!

代码:

var select = function(s) {
    return document.querySelector(s);
  },
  selectAll = function(s) {
    return document.querySelectorAll(s);
  },
  animationWindow = select('#animationWindow'),
  animData = {
    wrapper: animationWindow,
    animType: 'svg',
    loop: false,
    prerender: false,
    autoplay: false,
    path: 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/35984/egg_flip.json'
  },
  anim;

anim = bodymovin.loadAnimation(animData);
anim.addEventListener('DOMLoaded', onDOMLoaded);
anim.setSpeed(15);

function onDOMLoaded(e) {

  animationWindow.onclick = function(e) {
    if (anim.currentFrame > 0) {
      anim.playSegments([anim.currentFrame, 0], true);
      TweenMax.to('.eggGroup', 1, {
        x: 0,
        ease: Elastic.easeOut.config(0.9, 0.38)
      })
    } else {
      TweenMax.to('.eggGroup', 1.4, {
        x: 73,
        ease: Elastic.easeOut.config(0.9, 0.38)
      })
      anim.playSegments([anim.currentFrame, 300], true)
    }
  }
}
  body {
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

body,
html {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
}

#animationWindow {
  width: 50%;
  ;
  height: 50%;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
<div id="animationWindow">
</div>

最佳答案

来自 TweenMax documentation : 使用 onComplete 属性将函数作为回调传递。例如:

TweenMax.to('.eggGroup', 1.4, {
    x: 73,
    ease: Elastic.easeOut.config(0.9, 0.38),
    onComplete: function(){ ** do something ** };
})

关于javascript - 切换后链接页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51546020/

相关文章:

android - Skype For Business 在 Android 上的对话中不显示 HTML

css:将图像 float 到左侧 - 问题

php - 在 PHP 或 HTML/CSS 中是否有类似于 ASP.NET 母版页的内容?

javascript - 组合函数添加新参数

javascript - Jade(Pug) Html 渲染输出

javascript - Ajax创建动态div不支持点击功能,为什么?

javascript - 管理窗口尺寸

jquery - 如何将选中的 ="checked"属性添加到 .html() 方法的输出

html - 3 DIV's - Center Middle 和其他占用剩余空间

css - Gulp-sass 编译 scss 文件失败