javascript - 动画后未触发过渡

标签 javascript jquery html css

我制作了一个搜索模式,它是通过 jQuery 触发的,jQuery 将类 -open 添加到主父 div #search-box。我的问题是 #search-box 会淡入,但 input 不会转换。我不确定为什么会这样。 Here is a link to the full codepen

  #search-box {
     display: none;
     position: absolute;
     height: 100%;
     width: 100%;
     position: fixed;
     top: 0;
     left: 0;
     right: 0;
     z-index: 999999999;

     input {
        border-bottom: 2px solid white;
        display: block;
        width: 100%;
        transform: scale3d(0,1,1);
        transform-origin: 0% 50%;
        transition: transform 3s;
     }

     &.-open{
        background: rgba(0, 0, 0, .8);
        display: block;
        animation: fadein .8s;

        input{
           transform: scale3d(1,1,1);
           transition-duration: 10s;
           transition-delay: 2s;
         }
      }
  }

@keyframes fadein {
   from { opacity: 0; }
   to   { opacity: 1; }
}

这是jquery

$('a[href="#search"]').click(function() {
  $("#search-box").addClass("-open");
  setTimeout(function() {
    inputSearch.focus();
  }, 800);
});

$('a[href="#close"]').click(function() {
  $("#search-box").removeClass("-open");
});

最佳答案

原因是父级 #search-box 正在从 display: none 切换到 block 并且 css 转换不会触发该更改. 一些解决方案是使用 animation 缩放输入元素,或以其他方式隐藏 #search-box。就像使用 height:0; overflow:hiddenvisibility: hidden > visibility: visible.

关于javascript - 动画后未触发过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42224208/

相关文章:

javascript - z-index 图像在使用下一个上一个按钮时不显示,例如使用 jquery 的图像库

jquery - Bootstrap 4 导航栏未显示

python - 使用 Python 抓取 HTML

html - 传递给 Nav 2013 R2 的 SOAP 参数会导致错误,就好像它们为空一样

javascript - :inputText allow only decimal digits

javascript - 使用 Nodejs 在 mongodb 中存储文件

javascript - Web音频API:同时启动多个MediaElementAudioSourceNode

javascript - 随机出现的多个 Canvas 图像

javascript - 工作结束后得到一根绳子

javascript - 前置 jquery 验证错误消息