jquery - Bootstrap collapse 可以隐藏,但不能显示

标签 jquery html css twitter-bootstrap absolute

简而言之,这正在发生:https://jsfiddle.net/exr4hv8z/2/ (尝试将鼠标悬停在按钮上,然后将鼠标移开几次)

无论出于何种原因,元素折叠起来隐藏得很好,但是应该折叠起来以查看的另一个元素不会动画,并且在另一个元素完成后简单地弹出。

HTML:

<div id="nav_bar">

<a href="index.php">
    <div class="navbutton_background background_normal collapse in"></div>
    <div class="navbutton_background background_hover collapse" style="height: 0;"></div>
    <div class="navbutton_background background_click collapse" style="height: 0;"></div>
    <button class="navbutton rightborder">Home</button>
</a>

<a href="forum.php">
    <div class="navbutton_background background_normal collapse in left_1"></div>
    <div class="navbutton_background background_hover collapse left_1" style="height: 0;"></div>
    <div class="navbutton_background background_click collapse left_1" style="height: 0;"></div>
    <button class="navbutton leftborder rightborder left_1">Forums</button>
</a>

<a href="servers.php">
    <div class="navbutton_background background_normal collapse in left_2"></div>
    <div class="navbutton_background background_hover collapse left_2" style="height: 0;"></div>
    <div class="navbutton_background background_click collapse left_2" style="height: 0;"></div>
    <button class="navbutton leftborder rightborder left_2">Servers</button>
</a>

<a href="contact.php">
    <div class="navbutton_background background_normal collapse in left_3"></div>
    <div class="navbutton_background background_hover collapse left_3" style="height: 0;"></div>
    <div class="navbutton_background background_click collapse left_3" style="height: 0;"></div>
    <button class="navbutton leftborder rightborder left_3">Contact</button>
</a>

<a href="about.php">
    <div class="navbutton_background background_normal collapse in left_4"></div>
    <div class="navbutton_background background_hover collapse left_4" style="height: 0;"></div>
    <div class="navbutton_background background_click collapse left_4" style="height: 0;"></div>
    <button class="navbutton leftborder left_4">About</button>
</a>

</div>

CSS:

#nav_bar
{
background-color: rgba(27, 27, 27, 1);

width: 100%;
height: 5rem;

border-width: 10%;

margin-top: 2rem;

position: relative;
}

.navbutton
{
background-color: rgba(0, 0, 0, 0);
color: rgba(10, 10, 10, 1);

font-weight: bold;

width: 20%;
height: 100%;

position: absolute;

z-index: 1;

border: 0;
border-bottom: 0.5rem solid rgba(0, 0, 0, 0.2);
}

.navbutton_background
{
width: 20%;
height: 100%;

position: absolute;
}

/* Colors for button states */
.background_normal { background-color: rgba(40, 40, 40, 1); }
.background_hover { background-color: rgba(0, 190, 220, 1); }
.background_click { background-color: rgba(0, 210, 240, 1); }

/* Left_# are for positioning each individual button 20*#% away from the left side */
.left_1 { left: 20%; }
.left_2 { left: 40%; }
.left_3 { left: 60%; }
.left_4 { left: 80%; }

.leftborder { border-left: 0.3rem dashed rgba(27, 27, 27, 1); }
.rightborder { border-right: 0.3rem dashed rgba(27, 27, 27, 1); }

JS:

$(document).ready (function () {
    $("#nav_bar a").mouseover (function () {
        $(this).find (".background_normal").collapse ('hide');
        $(this).find (".background_hover").collapse ('show');
    });
    $("#nav_bar a").mouseout (function () {
        $(this).find (".background_hover").collapse ('hide');
        $(this).find (".background_normal").collapse ('show');
    });
});

编辑:我找到了解决该问题的方法,但我并不真正认为它是一个答案,因为它不会以任何方式阻止或修复此问题。我最终在其余元素下方添加了另一个元素,该元素在鼠标悬停/鼠标移出时更改了颜色,以模仿未正确折叠的元素。更新 fiddle :https://jsfiddle.net/exr4hv8z/3/

最佳答案

改用这个:

$(document).ready (function () {
    $("#nav_bar a").hover (function () {
        $(this).find (".background_normal").collapse ('hide');
        $(this).find (".background_hover").collapse ('show');
    },
    function () {
        $(this).find (".background_hover").collapse ('hide');
        $(this).find (".background_normal").collapse ('show');
    });
});

关于jquery - Bootstrap collapse 可以隐藏,但不能显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29442318/

相关文章:

javascript - 如何在单击单选按钮时更改输入文件的 "accept"值

html - 更正 Explorer 的 Flexbox 前缀

javascript - 如何使用 jQuery 执行脚本直至其加载

css - CSS 中的重叠元素

使用 HTML 页面包含页面时 jQuery 不工作

php - 无法在 Google 文档查看器中嵌入 .doc、docx 文件

javascript - 使用相应的标签序列化表单

php - 使用 Ajax 的异步 PHP 查询?

jquery - 获得第 n 个 child

javascript - 通过减小字体大小使文本适合固定高度和固定宽度的 div