简体   繁体   English

悬停的反弹效果 <ul> 在其中被观察到 <li> 儿童元素也是如此

[英]The bounce effect on hover over <ul> is observed in its <li> child elements as well

OK, So after a lot of stress and coffee I came with this code to show some bounce effect on child elements of by hovering over the link. 好吧,所以在经过大量的压力和咖啡之后,我带着这个代码,通过将鼠标悬停在链接上来显示对子元素的一些反弹效果。 And on moving the mouse away from the link the child elements hide after a delay of 4 secs. 在将鼠标移离链接时,子元素会在延迟4秒后隐藏。 This 4 sec delay was introduced because after hovering over the link people tend to immediately hover the mouse over the dropped down menu and because of the bounce effect a gap was getting created between the and 引入4秒延迟是因为在将鼠标悬停在链接上之后,人们倾向于立即将鼠标悬停在下拉菜单上,并且由于弹跳效应,在和之间产生了间隙。

  • elements and when you hover over the gap the dropped menu disappears so visitors on the website wont know that they have to wait for the bounce to stop to hover over the menu so I introduced delay of 4 secs. 元素,当你将鼠标悬停在间隙上时,删除的菜单消失,因此网站上的访问者不会知道他们必须等待弹跳停止悬停在菜单上,所以我引入了4秒的延迟。 Now the problem is that when I immediately try to move the mouse on the dropped menu the bounce effect reproduces itself on the child elements, I mean the bounce effect takes place twice, this happens only by immediately hovering over the dropped menu specially trying to hover over the first option in the menu. 现在的问题是,当我立即尝试在掉落的菜单上移动鼠标时,弹跳效果会在子元素上重现,我的意思是弹跳效果会发生两次,这只会通过立即将鼠标悬停在专门尝试悬停的下拉菜单上来实现超过菜单中的第一个选项。 So this looks ugly and at the same time shows poor coding, Is there a way to stop this from happening. 所以这看起来很难看,同时显示编码不好,有没有办法阻止这种情况发生。 And I also wanted to know that is there a way to toggle visibility using jQuery, I cannot use display option and I also cannot use removeClass function. 我还想知道有没有办法使用jQuery切换可见性,我不能使用display选项,我也不能使用removeClass函数。 I know, might sound little stringent criteria but to maintain the smoothness of rest of my code i need to take care of above two things. 我知道,可能听起来没有什么严格的标准,但为了保持我的代码的其余部分的顺畅,我需要处理上述两件事。 DEMO DEMO

    HTML Code: 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 Code 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; }​ 
  • How about animating the parent as well - something like: 如何为父母制作动画 - 例如:

    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/ http://jsfiddle.net/kGqRM/187/

    where padding is added to the bottom of the parent at the same rate as the submenu is moved 其中padding以与子菜单移动相同的速率添加到父级的底部

    Unfortunately this means that the li has to be a block element and floated left (so that the element is actually rendered properly - if you currently inspect your li it seems to be all squished to the left which is why you are leaving it when you try to go onto the child) 不幸的是,这意味着li必须是一个块元素并向左浮动(以便元素实际上正确呈现 - 如果你目前正在检查你的li,它似乎都被压缩到左边,这就是为什么你在尝试时离开它去看孩子)

    声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM