http://jsfiddle.net/jerrypeng0112/ahm7q1bq/ 我已经花了一些时间来解决这个问题,让它工作的唯一方法是为
`<body>
<header id="header">
<nav>
<ul id="main">
<li><a href="#">Home</a>
</li>
<li> <a href="#">About</a>
<ul class="hidden">
<li><a href="#">About 1</a>
</li>
<li><a href="#">About 2</a>
</li>
<li><a href="#">About 3</a>
</li>
</ul>
</li>
<li> <a href="#">Services</a>
<ul class="hidden">
<li><a href="#">Services 1</a>
</li>
<li><a href="#">Services 2</a>
</li>
<li><a href="#">Services 3</a>
</li>
</ul>
</li>
<li> <a href="#">History</a>
<ul class="hidden">
<li><a href="#">The History of This Site</a>
</li>
<li><a href="#">The History of The Web</a>
</li>
<li><a href="#">The History of Whatever</a>
</li>
</ul>
</li>
<li><a href="#">Contact</a>
</li>
</ul>
</nav>
</header>
</body>`
这是CSS
body {
margin:0;
padding:0;
height:1000px;
background: #39a;
font-family:arial;
}
header {
z-index:2;
position: fixed;
width: 100%;
height: 60px;
background: #222;
}
nav {
float:left;
}
nav ul {
list-style-type:none;
margin:0;
padding:0;
}
nav ul li {
display:inline-block;
float:left;
}
nav ul li a {
display:block;
width:80px;
height:60px;
text-align:center;
text-decoration:none;
line-height:60px;
color:white;
background:#404040;
}
nav ul li a:hover {
background:darkgray;
}
nav ul li:hover ul {
display:block;
}
nav ul li:hover ul a {
background:#404040;
color:white;
height:60px;
line-height:60px;
}
ul.hidden {
display:none;
position:absolute;
border-top:white solid 2px;
}
ul.hidden li {
display:block;
float:none;
}
ul.hidden li a {
width:auto;
min-width:80px;
padding:0 20px;
}
ul.hidden li a:hover {
background:darkgray;
}
这是脚本
$(document).ready(function () {
var width = $(window).width();
if (width > 800) {
$('ul li').hover(function () {
$('ul.hidden'.this).filter(':not(:animated)').slideDown(500);
},
function () {
$('ul.hidden'
this).fadeOut(500);
});
}
});
答案 0 :(得分:0)
http://jsfiddle.net/rcz0zt0v/20/
如果您要将jQuery用于动画,则不需要:hover来定义块
$(document).ready(function () {
$('ul .dropdown').on('mouseenter', function(e){
$(this).find('ul').slideDown(200);
}).on('mouseleave', function(){
$(this).find('ul').slideUp(100);
});
});