【问题标题】:Bootstrap collapse works to hide, but not to showBootstrap 折叠可以隐藏,但不能显示
【发布时间】:2015-04-05 06:05:05
【问题描述】:

简而言之,这正在发生: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');
    });
});

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

【问题讨论】:

    标签: jquery html css twitter-bootstrap absolute


    【解决方案1】:

    改用这个:

    $(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');
        });
    });
    

    【讨论】:

      猜你喜欢
      • 2017-07-21
      • 1970-01-01
      • 1970-01-01
      • 2018-11-28
      • 1970-01-01
      • 2017-10-08
      • 1970-01-01
      • 1970-01-01
      • 2019-06-13
      相关资源
      最近更新 更多