[英]javascript: how do I make one element visible relative to an element I hover over?
http://jsfiddle.net/awfex/4/ http://jsfiddle.net/awfex/4/
HTML: HTML:
<div class="section-header section-header-on" id="section_header_289" style="left: 50px;">
<span class="collapse"></span>
<div class="section-name">
<span class="name">Testing Facebox suff</span></div>
<ul class="tools">
<li>
<a class="trash" href="#"></a>
</li>
<li>
<a href="#" class="edit"></a>
</li>
</ul>
<div class="clear"></div>
</div>
js: js:
$j = jQuery.noConflict();
$j(".section-header").hover(function(){
$j(this).find("ul").show();
});
So, I need this to be relative, because there are multiple "section-header"s and the ID is generally unknown / generated by the app.所以,我需要这是相对的,因为有多个“section-header”并且ID通常是未知的/由应用程序生成。 But, basically, I want to be able to hover over the section-header, and then have ul.tools change from display: none;但是,基本上,我希望能够在节标题上使用 hover,然后将 ul.tools 从 display: none; 更改为to display: block.显示:阻止。 So I figured.show() could do that.所以我想.show() 可以做到这一点。 but.. I guess my selector is wrong.但是.. 我想我的选择器是错误的。 =\ =\
Your css specifies:您的 css 指定:
.section-header ul.tools,
.section-content li.content ul.tools {
visibility: hidden;
position: absolute;
top: 0;
left: -40px;
z-index: 1002;
cursor: default;
width: 40px;
height: 35px;
list-style: none;
}
Most notably visibility: hidden;
最显着的visibility: hidden;
which is not affected by the show()/hide()
functions.它不受show()/hide()
函数的影响。 So you need to change the css visibility property so your list will show-up.因此,您需要更改 css 可见性属性,以便显示您的列表。
Change:改变:
$j(this).find("ul").show();
To:至:
$j(this).find("ul").css({visibility: 'visible'});
Or set the CSS to display: none;
或者将 CSS 设置为display: none;
rather than use the visibility property.而不是使用可见性属性。
show()
documentation: http://api.jquery.com/show/ show()
文档: http://api.jquery.com/show/
Just needed a little css.只需要一点 css。
.tools {
display: none;
}
div.section-header:hover ul {
display: block;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.