简体   繁体   English

单击以显示时,如何始终显示隐藏的 div,位于其他 div 上方

[英]How to display hidden divs always 1st, above other divs when clicked to show

I am working on a bootstrap page (3.0).我正在处理引导页面(3.0)。 I have several small panels across the top of the page that are visible.我在页面顶部有几个可见的小面板。 Below these panels I have larger panels that contain much more detail of the small panels across the top that are hidden by default .在这些面板下方,我有更大的面板,其中包含默认情况下隐藏的顶部小面板的更多细节。 When a user clicks on one of the small panels across the top, it hides the small panel and displays hidden larger stacked vertical panels below it with the additional info.当用户单击顶部的小面板之一时,它会隐藏小面板并在其下方显示隐藏的较大堆叠垂直面板以及附加信息。

I need to make it so that whichever hidden panel is selected to open, that it will always show 1st (above all other visible divs).我需要做到这一点,无论选择打开哪个隐藏面板,它都将始终显示第一个(在所有其他可见 div 之上)。 The problem I am having is they are showing in the order the divs are hard coded in the HTML, however users will not see the new div load unless they scroll down to see it visible on the page.我遇到的问题是它们按照 div 在 HTML 中硬编码的顺序显示,但是用户不会看到新的 div 加载,除非他们向下滚动以在页面上看到它。 I need all newly clicked panels to load 1st, so users will always see it load above all other now visible divs.我需要所有新点击的面板加载第一个,所以用户总是会看到它加载在所有其他现在可见的 div 之上。

I am still learning jQuery/js.我还在学习 jQuery/js。

So, for my top (small) panels, I have a link in the panel-footer that opens the associated larger panels when clicked.因此,对于我的顶部(小)面板,我在面板页脚中有一个链接,可以在单击时打开相关联的较大面板。 It hides the small panel when clicked, then shows the hidden panel (adds a zommIn animation as well).单击时它会隐藏小面板,然后显示隐藏的面板(同时添加 zommIn 动画)。 Then when a user closes the larger panel, it hides it again, then adds the small panel back to the top panels.然后当用户关闭较大的面板时,它会再次隐藏它,然后将小面板添加回顶部面板。

It is all working great, I just need to prepend the hidden divs to ALWAYS display as 1st (above the other visible divs).一切都很好,我只需要在隐藏的 div 之前添加始终显示为第一个(在其他可见的 div 之上)。

Here is an example of the jQuery I am using to show the larger panels and hide the associated small top panels...这是我用来显示较大面板并隐藏关联的小顶部面板的 jQuery 示例...

//Device Panel
$("#openDashDevices").click(function(){
    $("#dashDevice").addClass("show zoomIn");
    window.setTimeout( function(){
          $("#dashDevice").removeClass("zoomIn");
        }, 1000);
    $("#dashDevice").removeClass("hide");
    $("#topPanelDevice").addClass("hide");
    $("#topPanelDevice").removeClass("show-inline zoomIn");                 

});

And here is the jQuery I am using that closes/hides the larger panels and re-shows the hidden small panel across the top...这是我正在使用的 jQuery,它关闭/隐藏较大的面板并重新显示顶部隐藏的小面板......

//Device Panel
$("#closeDevicePanel").click(function(){
    $("#dashDevice").addClass("hide");
    $("#dashDevice").removeClass("show zoomIn");
    $("#topPanelDevice").addClass("show-inline zoomIn");
    window.setTimeout( function(){
          $("#topPanelDevice").removeClass("zoomIn");
        }, 1000);
    $("#topPanelDevice").removeClass("hide");
});

HTML of ONE of the top panels:顶部面板上HTML:

<!--Dashboard Top Panels-->
<div class="dashboardPanelsGroup fivecolumns sortable">
    <div id="topPanelDevice" class="dashboardDevices dashboardPanels show-inline animated">
        <div class="panel panel-primary">
            <div class="panel-heading">
            <div class="dragPanelTop"><i class="fa fa-arrows"></i></div>
                <div class="row">
                    <div class="col-xs-3 dashIcon">
                        <i class="icon-device"></i>
                    </div>
                    <div class="col-xs-9 text-right">
                        <div class="huge">1344</div>
                        <div class="dashSubText">Computers</div>
                    </div>
                </div>
            </div>
            <a id="openDashDevices" class="dashPanelFooter" href="javascript:void(0);">
                <div class="panel-footer">
                    <span class="pull-left">View Devices</span>
                    <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                    <div class="clearfix"></div>
                </div>
            </a>
        </div>
    </div>
</div>

And here is the html of ONE of the larger panels (hidden by default)...这是其中一个较大面板的 html(默认情况下隐藏)...

<!--Opened Dashboard Panels-->
<div class="openedDashboardPanelsGroup sortable">
    <div id="dashDevice" class="dashboardDevices dashboardPanelsOpen col-sm-12 animated hide">
        <div id="panelDevices" class="panel panel-primary">
            <div class="panel-heading">
                <div class="dragPanelBottom"><i class="fa fa-arrows"></i></div>
                <div class="pull-right"><button id="closeDevicePanel" type="button" class="close" title="" rel="tooltip" data-original-title="Close Panel">×</button></div>
                <div class="row">
                    <div class="openDashTitle">
                        <div class=""><i class="dashIcon fa fa-bar-chart"></i>Devices</div>
                    </div>
                </div>
            </div>

            <div class="panelDashboardContent">
                <div id="maintStatsContent" class="maintenanceStats" type="maintenanceStats">        
                    Maint Stats goes here
                </div>
            </div>
        </div>
    </div>
</div>

Here is a screenshot showing my top panels and a couple of the larger panels opened...这是显示我的顶部面板和打开的几个较大面板的屏幕截图... 在此处输入图片说明

Instead of hard coding the html I would create it dynamically with jquery.我将使用 jquery 动态创建它,而不是对 html 进行硬编码。 That way you can just prepend it to the container.这样,你可以只是prepend它的容器。

$("#closeDevicePanel").click(function() {
    $('.containerclass').prepend('yourhtml');
}

I got it to work.我让它工作。 I just needed to use prependTo.我只需要使用 prependTo。 For example, to open the Alerts panel...例如,要打开警报面板...

//Alerts Panel
                    $("#openDashAlerts").click(function(){
                        $("#dashAlerts").prependTo(".openedDashboardPanelsGroup");
                        $("#dashAlerts").addClass("show zoomIn");
                        window.setTimeout( function(){
                              $("#dashAlerts").removeClass("zoomIn");
                            }, 1000);
                        $("#dashAlerts").removeClass("hide");
                        $("#topPanelAlerts").addClass("hide");
                        $("#topPanelAlerts").removeClass("show-inline zoomIn"); 
                    });

This now loads with my animation just like I need, and always prepends it as the 1st child of the parent div.现在就像我需要的那样加载我的动画,并且总是将它作为父 div 的第一个子级。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM