【问题标题】:Animated after element has delay and twitching元素有延迟和抽搐后的动画
【发布时间】:2020-09-25 11:38:55
【问题描述】:

我正在尝试为标题中的菜单项设置行为,如下所示:http://www.germanamericanconference.org/partners/。当悬停在元素上时,有一个来回滑动的栏。在我的情况下,我不能在我的标题中添加另一个元素,这种效果应该是纯 CSS,所以我使用 after 伪元素。

这里,在示例中:https://jsfiddle.net/1czmx08y/

正如您所见,在项目之间移动时会有延迟,但即使我减少过渡时间,它也会开始抽搐。

我怎样才能避免这种行为?我觉得我的过渡是错误的。

【问题讨论】:

    标签: css animation css-transitions transition pseudo-element


    【解决方案1】:

    将所有过渡改为0.15s或0.18s; 现在是不是好多了?我认为这会更好,它可能是比使用插件或更多 css 或任何 js 更好的选择。

    html {
      font-family: 'Josefin Slab', 'Comfortaa', sans-serif;
      font-size: 1.2em;
      background: #eee;
    }
    
    ul {
      position: relative;
      width: 27em;
      height: 2em;
      margin: 100px auto;
      padding: 0;
      white-space: nowrap;
    }
    
    ul li {
      display: inline;
      text-align: center;
    }
    
    ul li a {
      position: relative;
      top: 0;
      left: 0;
      right: 25em;
      bottom: 0;
      display: inline-block;
      -moz-box-sizing: border-box;
      box-sizing: border-box;
      padding: .4em .2em;
      color: #09C;
      text-decoration: none;
      text-shadow: 0 1px 0 white;
    
      /*transition*/
      -webkit-transition: width .3s,right .3s;
      -moz-transition: width .3s,right .3s;
      -o-transition: width .3s,right .3s;
      transition: width .19s,right .19s;
    }
    
    ul li:nth-child(1) a { width: 2em; }
    ul li:nth-child(2) a { width: 4em; }
    ul li:nth-child(3) a { width: 4em; }
    ul li:nth-child(4) a { width: 12em; }
    ul li:nth-child(5) a { width: 5em; }
    
    ul li:last-child a::after {
      content: "";
      position: absolute;
      right: inherit;
      bottom: -3px;
      width: inherit;
      height: 3px;
      background: #ccc;
      pointer-events: none;
      /*transition*/
      -webkit-transition: all .5s ease;
      -moz-transition: all .5s ease;
      -o-transition: all .5s ease;
      transition: all .19s ease;
    }
    
    ul li:nth-child(1) ~ li:last-child a {
      right: 25em;
      width: 2em;
    }
    
    ul li:nth-child(2):hover ~ li:last-child a {
      right: 21em;
      width: 4em;
    }
    
    ul li:nth-child(3):hover ~ li:last-child a {
      right: 17em;
      width: 4em;
    }
    
    ul li:nth-child(4):hover ~ li:last-child a {
      right: 5em;
      width: 12em;
    }
    
    ul li:nth-child(5):last-child:hover a {
      right: 0;
      width: 5em;
    }
    
    ul li:hover ~ li:last-child a::after,
    ul li:last-child:hover a::after { background: #c351fa; }
    
    ul li:last-child a {
      min-width: 5em;
      max-width: 5em;
    }
    
    ul li a:hover,
    ul li a:focus {
      color: #c351fa;
      background-color: rgba(255,255,255,.6);
    
      /*transition*/
      -webkit-transition: width .3s,right .3s,background-color .3s;
      -moz-transition: width .3s,right .3s,background-color .3s;
      -o-transition: width .3s,right .3s,background-color .3s;
      transition: width .19s,right .19s,background-color .19s;
    }
    
    ul li a:focus { border-bottom: 3px solid #c351fa; }
    <ul>
       <li><a href="#"> &#10047; </a></li><!--
    --><li><a href="#"> Lorem </a></li><!--
    --><li><a href="#"> Ipsum </a></li><!--
    --><li><a href="#"> Consectetur adipisicing </a></li><!--
    --><li><a href="#"> Sit amet </a></li>
     </ul>

    【讨论】:

    • 这个解决方案有点帮助,但现在它有点抽搐,不太顺畅。 :( 我希望它可以非常接近我分享的示例。
    • 那是一个插件或js。整个网络是一个框架,但你只使用 css ......当然这会使过渡更好,但会使网络变慢。我在过渡方面做更多工作,然后再看看。
    • 我把它们改成了 19 秒,我认为它是最好的 CSS,因为没有延迟,而且它的移动速度也不快。
    • 我同意你的看法。 :) 我想我可以把它当作一个解决方案,非常感谢你调查这个问题!
    猜你喜欢
    • 1970-01-01
    • 2020-08-24
    • 1970-01-01
    • 2021-04-22
    • 1970-01-01
    • 1970-01-01
    • 2013-01-03
    • 2012-01-07
    相关资源
    最近更新 更多