【发布时间】:2012-01-15 13:00:38
【问题描述】:
已编辑***感谢您提供以下帮助。我现在理解 $(this).children() 并且我让它工作了......有点。我需要一些帮助才能 100% 完成。
我有一个图标列表,点击后,我将其设置为打开相应图标下方的工具提示和下拉菜单。
所有图标都有相同的类。所有下拉列表看起来都一样(并且具有相同的类),我在 jQuery 代码中使用一个类作为工具提示和下拉列表。
我现在看到,通过使用 .children() 它将首先拉出直接孩子。它正在使用 .hover() 来显示工具提示。但是,对于其他效果(扩大工具提示、滑动下拉菜单,您可以在代码中看到),在 .click() 上没有任何反应。我一直添加 $(this).children() 所以不知道为什么它在一个地方有效,而在另一个地方无效。非常感谢任何和所有帮助。也感谢您迄今为止的帮助。
现在是代码... (请原谅我的缩进不是很好,我不确定我是否是唯一一个在将内容复制/粘贴到这里时遇到问题的人,但它总是搞砸了。我已经修复了一些,但不是 100%)
HTML:
<div class="topIcon">
<a href="stream.html"><img src="icons/stream16lg.png" /></a>
<div class="topIconNew"></div>
<div class="topTip">
<div class="topTipText">Stream</div>
</div>
<div class="topDrop">What's up</div>
</div>
jQuery:
$(document).ready(function() {
var clicked = false;
// tooltip hover
$("div.topIconNew, div.topIcon, div#topSend, div#topTool").hover(
function(){$(this).children("div.topTip").show();},
function(){
if(!clicked) {
$(this).children("div.topTip").hide();
$(this).children('div.topTip').hide();
}
}
);
//tooltip widening and dropdown menu
$("div.topIconNew").click(function(){
//permanent tooltip
$(this).children("div.topTip").show();
$(this).children("div.topTip").animate({width:320,marginLeft:-240},"fast");
$(this).children("div.topDrop").slideDown(240);
clicked = true;
});
$("div.wrapper").click(function(){
//hide dropdown (hide simultaneously)
$(this).children("div.topDrop, div.topTip").hide();
});
});
【问题讨论】:
-
我已经更新了下面的答案,以使用您在上面发布的代码。
标签: jquery html css drop-down-menu