3

好的,所以在经历了很多压力和咖啡之后,我提出了这段代码,通过将鼠标悬停在链接上来显示对子元素的一些反弹效果。并且在将鼠标从链接上移开时,子元素会在延迟 4 秒后隐藏。引入这个 4 秒延迟是因为在将鼠标悬停在链接上之后,人们往往会立即将鼠标悬停在下拉菜单上,并且由于反弹效果,在和

  • 元素,当您将鼠标悬停在间隙上时,下拉菜单会消失,因此网站上的访问者不会知道他们必须等待反弹停止才能将鼠标悬停在菜单上,因此我引入了 4 秒的延迟。现在的问题是,当我立即尝试在下拉菜单上移动鼠标时,反弹效果会在子元素上重现,我的意思是反弹效果会发生两次,这只有通过立即悬停在下拉菜单上特别试图悬停才会发生超过菜单中的第一个选项。所以这看起来很丑陋,同时显示出糟糕的编码,有没有办法阻止这种情况发生。而且我还想知道有没有办法使用 jQuery 切换可见性,我不能使用显示选项,也不能使用 removeClass 函数。我知道, 演示

    HTML 代码:

    <div id="menu">
        <ul class="menu" id="tempMenu">
            <li class="listOfNumbers">
                <a id="Menus" href="">Numbers</a>
                <ul class="submenu">
                    <li>
                        <a id="one" href="">one</a>
                    </li>
                    <li>
                        <a id="two" href="">two</a>
                    </li>
                    <li>
                        <a id="three" href="">three</a>
                    </li>
                    <li>
                        <a id="four" href="">four</a>
                    </li>
                    <li>
                        <a id="five" href="">five</a>
                    </li>
                    <li>
                        <a id="six" href="">six</a>
                    </li>
                    <li>
                        <a id="seven" href="">seven</a>
                    </li>
                    <li>
                        <a id="eight" href="">eight</a>
                    </li>
                </ul>
            </li>
        </ul>
    </div>​
    

    CSS 代码

    ul { margin:0; padding:0; width:0; }
    
    ul li {
        height: 30px;
        line-height: 30px;
        list-style: none;
    }
    
    ul.menu li a {
    
        padding:0;
        width:90px;
        display:block;
    
        color: #fff;
        font-size: 12px;
        font-weight: bolder;
        text-shadow: #000 0 -1px 1px;
        text-decoration: none;
        text-align: center;
    
        border-top: 1px solid #666;
        border-left: 1px solid #666;
        border-right: 1px solid #000;
        border-bottom: 1px solid #000;
    
        box-shadow: white 7px 5px 20px; /* W3 Standarts */
        -o-box-shadow: white 7px 5px 20px; /* Opera */
        -ms-box-shadow: white 7px 5px 20px; /* IE 10+ */
        -moz-box-shadow: white 7px 5px 20px; /* Firefox */
        -webkit-box-shadow:white 7px 5px 20px; /* Webkit */
    
        transition: text-shadow .7s ease-out,
                    background .7s ease-out; /* W3 Standarts */
        -o-transition: text-shadow .7s ease-out,
                       background .7s ease-out; /* Opera */
        -ms-transition: text-shadow .7s ease-out,
                        background .7s ease-out; /* IE 10+ */
        -moz-transition: text-shadow .7s ease-out,
                         background .7s ease-out; /* Firefox */
        -webkit-transition: text-shadow .7s ease-out,
                            background .7s ease-out; /* Webkit */
        background: linear-gradient(to bottom, rgba(76,76,76,1) 0%,rgba(89,89,89,1) 12%,rgba(102,102,102,1) 25%,rgba(71,71,71,1) 39%,rgba(17,17,17,1) 60%,rgba(0,0,0,1) 77%,rgba(19,19,19,1) 91%);
    
        background: -moz-linear-gradient(top, rgba(76,76,76,1) 0%, rgba(89,89,89,1) 12%, rgba(102,102,102,1) 25%, rgba(71,71,71,1) 39%, rgba(17,17,17,1) 60%, rgba(0,0,0,1) 77%, rgba(19,19,19,1) 91%);
        /* Webkit */
        background: #666 -webkit-gradient( linear, left bottom, left top, color-stop(0.3, rgb(00,00,00)), color-stop(0.9, rgb(80,80,80)) );
        /* Opera */
        background: #666 -o-gradient( linear, left bottom, left top, color-stop(0.3, rgb(00,00,00)), color-stop(0.9, rgb(80,80,80)) );
        /* IE 10+ */
        background: -ms-linear-gradient(top, rgba(76,76,76,1) 0%,rgba(89,89,89,1) 12%,rgba(102,102,102,1) 25%,rgba(71,71,71,1) 39%,rgba(17,17,17,1) 60%,rgba(0,0,0,1) 77%,rgba(19,19,19,1) 91%);
        /* IE6-9 */
        filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4c4c4c', endColorstr='#131313',GradientType=0 );
    }
    ul.menu .listOfNumbers {
        margin:15px 0 0 20px;
    }
    ul.menu li .submenu {
        top:30px;
        visibility:hidden;
    }
    ul.menu li:hover .submenu {
        visibility:visible;
        animation:mymove 1.2s linear; /* W3 Standart */
        -o-animation:mymove 1.2s linear; /* Opera */
        -ms-animation:mymove 1.2s linear; /* IE 10+ */
        -moz-animation:mymove 1.2s linear; /* Firefox */
        -webkit-animation:mymove 1.2s linear; /* Safari and Chrome */
    }
    ul.menu li:not(:hover) .submenu {
        top:30px;
        opacity:0;
        transition:opacity 1.2s linear 3s,
            visibility 1.2s linear 3s; /* W3 Standart */
        -o-transition:opacity 1.2s linear 3s,
            visibility 1.2s linear 3s; /* Opera */
        -ms-transition:opacity 1.2s linear 3s,
            visibility 1.2s linear 3s; /* IE 10+ */
        -moz-transition:opacity 1.2s linear 3s,
            visibility 1.2s linear 3s; /* Firefox */
        -webkit-transition:opacity 1.2s linear 3s,
            visibility 1.2s linear 3s; /* Safari and Chrome */
    }
    @keyframes mymove
    {
        0%   {opacity:0.1;margin-top:0px;}
        10%  {opacity:0.3;margin-top:25px;}
        30%  {opacity:0.4;margin-top:50px;}
        60%  {opacity:0.5;margin-top:25px;}
        80%  {opacity:0.7;margin-top:50px;}
        90%  {opacity:0.9;margin-top:35px;}
        95%  {opacity:0.95;margin-top:25px;}
        100% {opacity:1;margin-top:0px;}
    }
    /* Opera */
    @-o-keyframes mymove
    {
        0%   {opacity:0.1;margin-top:0px;}
        10%  {opacity:0.3;margin-top:25px;}
        30%  {opacity:0.4;margin-top:50px;}
        60%  {opacity:0.5;margin-top:25px;}
        80%  {opacity:0.7;margin-top:50px;}
        90%  {opacity:0.9;margin-top:35px;}
        95%  {opacity:0.95;margin-top:25px;}
        100% {opacity:1;margin-top:0px;}
    }
    /* IE 10+ */
    @-ms-keyframes mymove
    {
        0%   {opacity:0.1;margin-top:0px;}
        10%  {opacity:0.3;margin-top:25px;}
        30%  {opacity:0.4;margin-top:50px;}
        60%  {opacity:0.5;margin-top:25px;}
        80%  {opacity:0.7;margin-top:50px;}
        90%  {opacity:0.9;margin-top:35px;}
        95%  {opacity:0.95;margin-top:25px;}
        100% {opacity:1;margin-top:0px;}
    }
    /* Firefox */
    @-moz-keyframes mymove
    {
        0%   {opacity:0.1;margin-top:0px;}
        10%  {opacity:0.3;margin-top:25px;}
        30%  {opacity:0.4;margin-top:50px;}
        60%  {opacity:0.5;margin-top:25px;}
        80%  {opacity:0.7;margin-top:50px;}
        90%  {opacity:0.9;margin-top:35px;}
        95%  {opacity:0.95;margin-top:25px;}
        100% {opacity:1;margin-top:0px;}
    }
    /* Safari and Chrome */
    @-webkit-keyframes mymove
    {
        0%   {opacity:0.1;margin-top:0px;}
        10%  {opacity:0.3;margin-top:25px;}
        30%  {opacity:0.4;margin-top:50px;}
        60%  {opacity:0.5;margin-top:25px;}
        80%  {opacity:0.7;margin-top:50px;}
        90%  {opacity:0.9;margin-top:35px;}
        95%  {opacity:0.95;margin-top:25px;}
        100% {opacity:1;margin-top:0px;}
    }
    ul.menu .submenu li a {
        -webkit-border-top-left-radius:0px;
        -webkit-border-bottom-left-radius:0px;
        -webkit-border-top-right-radius:0px;
        -webkit-border-bottom-right-radius:0px;
        -moz-border-top-left-radius: 0px;
        -moz-border-radius-bottomleft:0px;
        -moz-border-top-right-radius: 0px;
        -moz-border-radius-bottomright: 0px;
        /* margin: 68px 95px; */
        z-index: 1000;
    }
    
    ul.menu .submenu li:first-child a {
        -webkit-border-top-left-radius:10px;
        -webkit-border-bottom-left-radius:2px;
        -webkit-border-top-right-radius:10px;
        -webkit-border-bottom-right-radius:2px;
        -moz-border-top-left-radius: 10px;
        -moz-border-radius-bottomleft:2px;    
        -moz-border-top-right-radius: 10px;
        -moz-border-radius-bottomright: 2px;
        border-top-left-radius: 10px;
        border-bottom-left-radius:2px;    
        border-top-right-radius: 10px;
        border-bottom-right-radius:2px;
        /* margin: 34px 95px; */
        z-index: 1000;
    }
    
    ul.menu .submenu li:last-child a {
        -webkit-border-top-left-radius:2px;
        -webkit-border-bottom-left-radius:10px;
        -webkit-border-top-right-radius:2px;
        -webkit-border-bottom-right-radius:10px;
        -moz-border-top-left-radius: 2px;
        -moz-border-radius-bottomleft:10px;
        -moz-border-top-right-radius: 2px;
        -moz-border-radius-bottomright: 10px;
        border-top-left-radius: 2px;
        border-bottom-left-radius:10px;    
        border-top-right-radius: 2px;
        border-bottom-right-radius:10px;
        /* margin:260px 95px; */
        z-index: 1000;
    }
    
    ​
    
  • 4

    1 回答 1

    1

    如何动画父母以及 - 比如:

    ul.menu > li:hover  {
        visibility:visible;
        animation:parentmove 1.2s linear; /* W3 Standart */
        -moz-animation:parentmove 1.2s linear; /* Firefox */
        -webkit-animation:parentmove 1.2s linear; /* Safari and Chrome */
    }
    
    @keyframes parentmove
    {
        0%   {padding-bottom:5px;}
        10%  {padding-bottom:30px;}
        30%  {padding-bottom:55px;}
        60%  {padding-bottom:30px;}
        80%  {padding-bottom:55px;}
        90%  {padding-bottom:40px;}
        95%  {padding-bottom:30px;}
        100% {padding-bottom:5px;}
    }
    

    http://jsfiddle.net/kGqRM/187/

    以与移动子菜单相同的速率将填充添加到父级的底部

    不幸的是,这意味着 li 必须是一个块元素并且向左浮动(以便该元素实际上被正确渲染 - 如果您当前检查您的 li 它似乎全部向左挤压,这就是您在尝试时离开它的原因去到孩子身上)

    于 2013-01-03T13:10:20.900 回答