.动画问题/帮助
所以,到目前为止我已经构建了这个导航栏,我很好奇它是否有可能实现我的想法。 目前,当您将鼠标悬停在每个链接上时,它们会下拉(填充会增加)。
现在,我很好奇做的是,如果您将鼠标悬停在“test1”上,test2-4 也会随之下降,但在从下拉列表中创建的填充中,会显示“test1”信息。允许用户单击或阅读其中的任何信息。另外,如果用户愿意,他们可以将鼠标移动到 test2,所有内容都会以动画形式(不透明度,我认为我可以做到)到 test2 字段中的任何内容,test3 执行相同的操作,依此类推。
我在这方面没有取得太大成功,我之前创建了一个完全独立的面板,但这并不完全有效,或者我没有正确执行。
这是我一直在努力的事情,任何帮助将不胜感激!谢谢!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function() {
$("#nav li > a").hover(function() {
$(this).stop().animate({paddingTop: "100px"}, 100);
},
function() {
$(this).stop().animate({paddingTop: "10px"}, 200);
});
});
</script>
<style type="text/css">
#nav
{
position: absolute;
top: 0;
left: 60px;
padding: 0;
margin: 0;
list-style: none;
}
#nav li
{
display: inline;
}
#nav li a
{
float: left;
display: block;
color: #555;
text-decoration: none;
padding: 10px 30px;
background-color: #d1d1d1;
border-top: none;
}
</style>
</head>
<body>
<div id="wrap">
<ul id="nav">
<li><a href="">test1</a></li>
<li><a href="">test2</a></li>
<li><a href="">test3</a></li>
<li><a href="">test4</a></li>
</ul>
</div>
</body>
</html>
So, I've built this navigation bar so far and I'm curious if it's even possible to achieve what I'm thinking.
Currently, when you hover over each of the links they drop down (padding is increased).
Now, what I'm curious in doing is if you hover over say "test1", test2-4 also drop with it but in the padding that has been created from the drop down, "test1" information shows up. Allowing the user to click or read whatever information is in there. Also, if the user would like to, they can move their mouse to test2 and everything would animate (opacity, this I can do I think) to whatever is in the test2 field, test3 doing the same and so on.
I haven't had much success with this, I've created a completely separate panel before, but that didn't exactly work or I wasn't doing it correctly.
Here is what I've been working on, ANY help would be appreciated! Thanks!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function() {
$("#nav li > a").hover(function() {
$(this).stop().animate({paddingTop: "100px"}, 100);
},
function() {
$(this).stop().animate({paddingTop: "10px"}, 200);
});
});
</script>
<style type="text/css">
#nav
{
position: absolute;
top: 0;
left: 60px;
padding: 0;
margin: 0;
list-style: none;
}
#nav li
{
display: inline;
}
#nav li a
{
float: left;
display: block;
color: #555;
text-decoration: none;
padding: 10px 30px;
background-color: #d1d1d1;
border-top: none;
}
</style>
</head>
<body>
<div id="wrap">
<ul id="nav">
<li><a href="">test1</a></li>
<li><a href="">test2</a></li>
<li><a href="">test3</a></li>
<li><a href="">test4</a></li>
</ul>
</div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我搞乱了你的代码,但没有得到完整的答案,但我想我还是会发布我所拥有的内容。此代码将在菜单上方添加一个 div,并使用它来显示
特定内容。我将 id 添加到您的
标记中,因为您在确定要显示的内容时需要某种方法来识别它们。我认为您确实不应该将
div
标记放入ul
中,因此这并不完美。然后我认为您的意思是您希望链接特定内容在您悬停时直接显示在链接上,并提出了不同的内容。您可以使用 jQuery 的 prepend 将特定内容添加到“填充”区域。使用此解决方案,您不需要
a
标签中的 id,但整个菜单不会在悬停时下拉(但它可能以某种方式被困在那里,可能会回到稍后再说)。要查看它,只需将您的 jQuery 代码更改为:我希望这能提供一些帮助。祝你好运!
编辑:当然,jQuery 的 html 方法将设置从其选择器返回的元素的innerHTML 。因此,在第一个示例中,
content
变量可以包含您想要用作链接的任何a
标记。下面是一个示例,显示如何为 test1 的内容创建几个链接:I messed around with your code some but didn't get a full answer, but figured I'd post what I have anyway. This code will add a div above the menu, and use that to display the
<a>
specific content. I added ids to your<a>
tags as you'd need some way to identify them when determining what content to show. I don't think you really should put adiv
tag in anul
, so this isn't perfect.I then thought that you meant you wanted your link specific content to show up directly over your links when you hover, and came up with something different. You can use jQuery's prepend to add the specific content to the 'padding' area. With this solution you don't need the ids in the
a
tags, but the whole menu doesn't drop down on hover (but it could somehow, I got kind of stuck there and may come back to it later). To see it just change your jQuery code to this:I hope this provides some help. Good luck!
Edit: Sure, jQuery's html method will set the innerHTML of the element(s) returned from its selector. So in the first example, the
content
variable can contain whatevera
tags you want to use as links. Here's an example showing to to create a couple links for test1's content: