Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 views
in Technique[技术] by (71.8m points)

html - Text showing before animation is done

I'm trying to create a dropdown animation, and I got it to work except the text. The text shows instantly before the animation is done. This makes the animation look really bad.

I hope you guys know how to fix something like this.

This is my code:

.drop-down-btn:hover + .drop-down {
    display: block!important;
}

.drop-down:hover {
    display: block!important;
}

.drop-down {
    display: none;
    position: absolute;
    background-color: #151C35;
    color: #626677;
    width: 200px;
    height: 252px;
    z-index: 999;
    border-left: 3px solid #5A93FF;
}

.drop-down a {
    padding: 10px;
    display: block;
    color: #626677;
}

.drop-down a:hover {
    background-color: #2b3146;
    color: white;
    text-decoration: none;
}

@keyframes drop-down-animation {
    from {
        height: 0px;
    }

    to {
        height: 252px;
    }
}

.drop-down-animation {
    animation-name: drop-down-animation;
    -webkit-animation-name: drop-down-animation;
}

.animated {
    animation-duration: .3s;
    animation-fill-mode: both;
    -webkit-animation-duration: .3s;
    -webkit-animation-fill-mode: both
}
<a class="drop-down-btn">Dropdown btn <i class="fas fa-caret-down"></i></a>
<div class="drop-down drop-down-animation animated">
  <a href="#"><i class="fas fa-database fa-fw"></i> test</a>
  <a href="#"><i class="fas fa-server fa-fw"></i> test</a>
  <a href="#"><i class="fas fa-cloud fa-fw"></i> test</a>
  <a href="#"><i class="fas fa-globe fa-fw"></i> test</a>
  <a href="#"><i class="fab fa-discord fa-fw"></i> test</a>
  <a href="#"><i class="fas fa-globe fa-fw"></i> test</a>
</div>
question from:https://stackoverflow.com/questions/66060429/text-showing-before-animation-is-done

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you can add overflow: hidden to the .drop-down class and make it when the drop appear the list appear with it and hide the out of the drop.

.drop-down {
   display: none;
   position: absolute;
   background-color: #151C35;
   color: #626677;
   width: 200px;
   height: 252px;
   z-index: 999;
   border-left: 3px solid #5A93FF;
   overflow: hidden;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...