简体   繁体   English

javascript:如何使一个元素相对于我 hover 的元素可见?

[英]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.但是.. 我想我的选择器是错误的。 =\ =\

Demo演示

just needed a little coercion;)只需要一点强制;)

$j = jQuery.noConflict();
$j(".section-header").hover(function(){
    $j(this).find(".tools").css({visibility:"visible"});
},function(){
    $j(this).find(".tools").css({visibility:"hidden"});
});

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.

相关问题 Hover 覆盖一个元素以使不同的元素可见 - Hover over one element to make a different element visible 如何将一个元素精确地放置在另一个元素上? - How do I place one element precisely over another element? 如何使用VideoJS在全屏模式下使元素可见 - How Do I Make An Element Visible in Fullscreen Mode With VideoJS 如何使 javascript 更改 rails 中特定元素的元素 - How do I make javascript change the element of specific element in rails 当其他元素悬停在元素上时,如何更改:hover状态? - How do I change :hover status on an element when a different element is hovered over? Javascript:将鼠标悬停在一个元素上时,如何定位幻灯片中的选定元素? - Javascript: How do i target selected elements in a slideshow when hovering over one element? 如何使用 javascript 获取 div 元素相对于另一个 div 元素的内容? - how do I get the content of a div element relative to another div element using javascript? 当我 hover 在导航栏元素本身上时,我的子导航栏是可见的,但当我在它上面时,我的子导航栏消失了 hover - my sub navigation bar is visible when i hover over the navbar element itself but disappears when i hover over it 如果没有<a>元素,如何在 iPhone 上修复:hover?</a> - How do i fix :hover on iPhone if there is no <a> element? 如何检查鼠标是否在javascript中的元素上? - How do I check if the mouse is NOT over an element in javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM