【问题标题】:CSS ::after selector animates slowerCSS ::after 选择器动画变慢
【发布时间】:2014-03-01 05:56:44
【问题描述】:

所以我有一个下拉菜单,一旦点击链接就会淡入。单击链接后,一切都很好,菜单会淡入,但是一旦我单击关闭并且运行的功能会淡出下拉菜单。盒子顶部的三角形的淡出速度比实际盒子要慢一些。在 css 中,我用 :after 选择器制作了这个三角形,可以找到一个小提琴 JsFiddle

HTML

<a href="#" class="Header-Link Right Account-Actions"><?php echo 'Welcome ' . $user->data()->fname . '!'; ?></a>
        <div class="Account-Links">
            <a href="#" class="Account-Link">My Account</a>
            <a href="logout.php" class="Account-Link">Sign Out</a>
            <a href="#" class="Account-Link">Help</a>
        </div>

CSS

.Account-Actions {
    postition: relative;
}

.Account-Links {
    position: absolute;
    top: 45px;
    left: 0;
    display: block;
    visibility: hidden;
    margin: 0;
    padding: 0;
    width: 200px;
    height: 0;
    opacity: 0;
    box-sizing: border-box;
    background-color: rgba(0,0,0,.7);
    z-index: 1000;
    transition: all .2s ease-in-out;
    -moz-transition: all .2s ease-in-out;
    -webkit-transition: all .2s ease-in-out;
    -o-transition: all .2s ease-in-out;
}

.Account-Links-On {
    height: auto;
    visibility: visible;
    opacity: 1;
}

.Account-Links::after {
    position: absolute;
    top: -8px;
    right: 22px;
    content: '';
    width: 0;
    height: 0;
    border-bottom: solid 8px rgba(0,0,0,.7);
    border-left: solid 8px transparent;
    border-right: solid 8px transparent;
}

.Account-Link {
    display: block;
    color: #FFF;
    margin: 0;
    padding: 10px;
}

.Account-Link:hover {
    background-color: rgba(231,76,60,.75);
}

a {
    text-decoration: none;
}

a.Header-Link {
    position: relative;
    display: block;
    margin: 0 10px;
    padding: 0 8px;
    line-height: 47px;
    color: #777;
    border-bottom: 3px solid transparent;
}

a.Header-Link:hover {
    color: #000;
}

JS

$(document).ready(function(){
        $('.Account-Actions').bind('click', function(){
            $('.Account-Links').toggleClass('Account-Links-On');
        });

        $('html').click(function() {
            $('.Account-Links').removeClass('Account-Links-On');
        });

        $('.Account-Links, .Account-Actions').click(function(event){
            event.stopPropagation();
        });
    });

【问题讨论】:

    标签: javascript jquery html css drop-down-menu


    【解决方案1】:

    您已在不同的class 上创建了该箭头,并在其他class 上切换了不透明度。你的箭头不应该在.Account-Links。如果您不希望发生这种延迟,它应该在 .Account-Links-On 上。

    SEE THE DEMO

    .Account-Links-On::after {
      position: absolute;
      top: -8px;
      right: 22px;
      content: '';
      width: 0;
      height: 0;
      border-bottom: solid 8px rgba(0,0,0,.7);
      border-left: solid 8px transparent;
      border-right: solid 8px transparent;
    }
    

    由此得出的结论是 :after 伪选择器的动画不会变慢。

    【讨论】:

      猜你喜欢
      • 2022-01-22
      • 2010-12-27
      • 1970-01-01
      • 2011-07-23
      • 1970-01-01
      • 2021-12-24
      • 2011-06-18
      • 2021-07-31
      相关资源
      最近更新 更多