javascript - Change column width on click in bootstrap 3 - Stack Overflow

How to switch the size of one column when there is a click on a sidebar?Im developing an application wi

How to switch the size of one column when there is a click on a sidebar?

Im developing an application with a map in a column and a second column to the right displaying information. There is a sidebar that slides in from the right when activated.

When the sidebar is extended, the main column with the map is col-lg-6 and the column on the right is col-lg-4

Now when the sidebar is closed by clicking on a button, I would like to map column to switch to col-lg-8. Is there a way to do this?

Code for page and sidebar:

<div id="container">
  <div id="sidebar">
    <div class="sidebar-wrapper">
      <div class="panel panel-default" id="features">
        <div class="panel-heading">
          <h3 class="panel-title">Projects
          <button type="button" class="btn btn-xs btn-default pull-right" id="sidebar-hide-btn"><i class="fa fa-chevron-left"></i></button></h3>
        </div>
        <div class="panel-body">
          <div class="row">
            <div class="col-xs-8 col-md-8">
              <input type="text" class="form-control search" placeholder="Filter" />
            </div>
            <div class="col-xs-4 col-md-4">
              <button type="button" class="btn btn-primary pull-right sort" data-sort="feature-name" id="sort-btn"><i class="fa fa-sort"></i>&nbsp;&nbsp;Sort</button>
            </div>
          </div>
        </div>
        <div class="sidebar-table">
          <table class="table table-hover" id="feature-list">
            <thead class="hidden">
              <tr>
                <th>Icon</th>
              <tr>
              <tr>
                <th>Name</th>
              <tr>
              <tr>
                <th>Chevron</th>
              <tr>
            </thead>
            <tbody class="list"></tbody>
          </table>
        </div>
      </div>
    </div>
  </div>

    <div class="row" style="margin-left:0px;">
    <div class="col-xs-12 col-sm-6 col-lg-6" style="padding:0;">
        <div id="map"></div>
    </div>
    <div class="col-xs-6 col-lg-4" style="padding-top:0px">
        <div class="row">
            <div class="col-xs-12 col-lg-12" style="padding-top:0px; padding-left:0; padding-right:0;">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <i class="fa fa-bar-chart fa-2x"></i>
                        </div>
                    <div class="panel-body" style="text-align:center">
                        <div id="chart"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
                <div class="col-xs-12 col-lg-12" style="padding-top:0px; padding-left:0; padding-right:0;">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <i class="fa fa-list fa-2x"></i>
                        </div>
                    <div class="panel-body" style="text-align:left">
                        <div id="projects"></div>
                    </div>
                    </div>
                </div>
        </div>
        </div>

    </div>
    </div>
</div>

Code for activation of sidebar and menu button:

$(window).resize(function () {
var h = $(window).height(),
    offsetTop = 50; // Calculate the top offset
$('#map').css('height', (h - offsetTop));
}).resize();

$("#list-btn").click(function() {
 $('#sidebar').toggle();
  map.invalidateSize();
  return false;
});

$("#sidebar-toggle-btn").click(function() {
  $("#sidebar").toggle();
  map.invalidateSize();
  return false;
});

$("#sidebar-hide-btn").click(function() {
  $('#sidebar').hide();
  map.invalidateSize();
});

EDIT

I have tried using toggleClass and addClass/removeClass but its not working. Here is a jsfiddle to show what happens when the sidebar is hidden.

/

How to switch the size of one column when there is a click on a sidebar?

Im developing an application with a map in a column and a second column to the right displaying information. There is a sidebar that slides in from the right when activated.

When the sidebar is extended, the main column with the map is col-lg-6 and the column on the right is col-lg-4

Now when the sidebar is closed by clicking on a button, I would like to map column to switch to col-lg-8. Is there a way to do this?

Code for page and sidebar:

<div id="container">
  <div id="sidebar">
    <div class="sidebar-wrapper">
      <div class="panel panel-default" id="features">
        <div class="panel-heading">
          <h3 class="panel-title">Projects
          <button type="button" class="btn btn-xs btn-default pull-right" id="sidebar-hide-btn"><i class="fa fa-chevron-left"></i></button></h3>
        </div>
        <div class="panel-body">
          <div class="row">
            <div class="col-xs-8 col-md-8">
              <input type="text" class="form-control search" placeholder="Filter" />
            </div>
            <div class="col-xs-4 col-md-4">
              <button type="button" class="btn btn-primary pull-right sort" data-sort="feature-name" id="sort-btn"><i class="fa fa-sort"></i>&nbsp;&nbsp;Sort</button>
            </div>
          </div>
        </div>
        <div class="sidebar-table">
          <table class="table table-hover" id="feature-list">
            <thead class="hidden">
              <tr>
                <th>Icon</th>
              <tr>
              <tr>
                <th>Name</th>
              <tr>
              <tr>
                <th>Chevron</th>
              <tr>
            </thead>
            <tbody class="list"></tbody>
          </table>
        </div>
      </div>
    </div>
  </div>

    <div class="row" style="margin-left:0px;">
    <div class="col-xs-12 col-sm-6 col-lg-6" style="padding:0;">
        <div id="map"></div>
    </div>
    <div class="col-xs-6 col-lg-4" style="padding-top:0px">
        <div class="row">
            <div class="col-xs-12 col-lg-12" style="padding-top:0px; padding-left:0; padding-right:0;">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <i class="fa fa-bar-chart fa-2x"></i>
                        </div>
                    <div class="panel-body" style="text-align:center">
                        <div id="chart"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
                <div class="col-xs-12 col-lg-12" style="padding-top:0px; padding-left:0; padding-right:0;">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <i class="fa fa-list fa-2x"></i>
                        </div>
                    <div class="panel-body" style="text-align:left">
                        <div id="projects"></div>
                    </div>
                    </div>
                </div>
        </div>
        </div>

    </div>
    </div>
</div>

Code for activation of sidebar and menu button:

$(window).resize(function () {
var h = $(window).height(),
    offsetTop = 50; // Calculate the top offset
$('#map').css('height', (h - offsetTop));
}).resize();

$("#list-btn").click(function() {
 $('#sidebar').toggle();
  map.invalidateSize();
  return false;
});

$("#sidebar-toggle-btn").click(function() {
  $("#sidebar").toggle();
  map.invalidateSize();
  return false;
});

$("#sidebar-hide-btn").click(function() {
  $('#sidebar').hide();
  map.invalidateSize();
});

EDIT

I have tried using toggleClass and addClass/removeClass but its not working. Here is a jsfiddle to show what happens when the sidebar is hidden.

http://jsfiddle/Monduiz/dzo5yg72/

Share Improve this question edited Oct 20, 2015 at 16:28 Monduiz asked Oct 19, 2015 at 18:20 MonduizMonduiz 72110 silver badges22 bronze badges 2
  • 1 api.jquery./toggleclass – Blazemonger Commented Oct 19, 2015 at 18:23
  • 2 Possible duplicate of jquery change class name – Drew Gaynor Commented Oct 19, 2015 at 18:38
Add a ment  | 

1 Answer 1

Reset to default 3

Try this type of trick:

$("#sidebar-hide-btn").click(function() {
    $('#sidebar').hide();
    $('#mapDiv').removeClass('col-lg-6');
    $('#mapDiv').addClass('col-lg-8');
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745537519a4631971.html

相关推荐

  • javascript - Change column width on click in bootstrap 3 - Stack Overflow

    How to switch the size of one column when there is a click on a sidebar?Im developing an application wi

    13小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信