在Bootstrap中的悬停中打开“折叠"选项卡 [英] Open Collapse Tab in Hover in Bootstrap

查看:119
本文介绍了在Bootstrap中的悬停中打开“折叠"选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Bootstrap中有折叠面板",单击该选项卡标题即可打开.我试图找出使用鼠标悬停在选项卡的总宽度上打开,但没有得到.下面是默认情况下关闭的单个标签的代码.

I am having Collapse Panel in Bootstrap which is opening on a click on the title of the tab. I am trying to figure out to open using the hover of the mouse on the total width of the tab but I am not getting it. Below is the code of the single tab which is close by default.

<div class="panel panel-default" style="background-color:#039;"> 
    <div class="panel-heading" style="background-color:#039;">
         <a  class="nodecoration panel-title lead" data-toggle="collapse" data-parent="#panel-814345" href="#panel-element-566205">Software Development</a>
    </div>
    <div id="panel-element-566205" class="panel-collapse collapse" style="background-color:#039; color:#fff;">
        <div class="panel-body" style="border:none; font-size:14px; padding-bottom:0; margin-bottom:0;">
            We work for almost all web based application, database-driven systems, mapping and geo-spatial applications, and large content managed websites
            <br /><br /><p style="font-style:italic; font-weight:700;">Find out more</p>
        </div>
    </div>
</div>

如果将css类从class="panel-collapse collapse"更改为class="panel-collapse collapse in",则选项卡将打开.您能否让我知道如何实现这一目标.

If we change the css class from class="panel-collapse collapse" to class="panel-collapse collapse in" then the tab is open. Could you please let me know how to achieve this.

我仅通过将鼠标悬停在标题上(而不是标签的总宽度上)来获得答案.代码低于

$(function() {
    $(document).on('mouseenter.collapse', '[data-toggle=collapse]', function(e) {
        var $this = $(this),
            href, target = $this.attr('data-target') || e.preventDefault() || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')
            ,
            option = $(target).hasClass('in') ? 'hide' : "show";
            $('.panel-collapse').not(target).collapse("hide");
            $(target).collapse(option);
    })
});

我们可以通过将鼠标悬停在整个宽度上来使它正常工作吗?

Can we make this to work by hover on the full width ??

推荐答案

您可以使用hover函数

$(".panel-heading").hover(
 function() {
    $('.panel-collapse').collapse('show');
  }, function() {
    $('.panel-collapse').collapse('hide');
  }
);

但是一旦鼠标离开标题标题,它将关闭面板

But it will close the panel as soon as mouse leaves the title header

用鼠标悬停小提琴

替代解决方案是mouseenter函数

$(".panel-heading").mouseenter(function () {
        $(".panel-collapse").fadeIn();
    });
 $(".panel-collapse").mouseleave(function(){
       $(".panel-collapse").fadeOut();
});

只有当鼠标离开面板主体时,面板才会关闭.

With this the panel only close when mouse leaves the panel body.

用鼠标点击小提琴

这篇关于在Bootstrap中的悬停中打开“折叠"选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆