javascript – onclick触发器调整大小,highcharts

我是jQuery世界的新手,我想在点击特定类时触发调整大小,我用Google搜索分配,但是找到任何解决方案.

我正在使用Highcharts,其中ill动态全宽度框添加到面板的父级,当全宽度框附加到div我想触发调整大小.

这是我实现的代码,但是dint得到了解决方案

// code for highcharts
$(function () {
    $('.highcharts_horizontal_stacked').highcharts({
        chart: {
            type: 'bar'
        },
        title: {
            text: 'Stacked bar chart'
        },
        xAxis: {
            categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Total fruit consumption'
            }
        },
        legend: {
            reversed: true
        },
        plotOptions: {
            series: {
                stacking: 'normal'
            }
        },
        series: [{
            name: 'John',
            data: [5, 3, 4, 7, 2]
        }, {
            name: 'Jane',
            data: [2, 2, 3, 2, 1]
        }, {
            name: 'Joe',
            data: [3, 4, 4, 2, 5]
        }]
    });
});


// for full width function
$('.full-width').click(function () {
  $(this).closest('[class^="col"]').toggleClass('full-width-box');
});


//function for resize
$(".full-width").click(function(e) {
  e.preventDefault();
  setInterval(function() {

    $(window).resize(function() {
      $('body').load( function(){
        $(window).trigger('resize');
      });
    })
  }, 1);
});
.full-width-box{
    width: 100%;
    z-index: 1;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<!-- Highcharts -->
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div class="row">
  <div class="col-xs-6">
    <div class="panel panel-default ">
      <div class="panel-heading">
        <h3 class="panel-title">Title</h3>
        <a href="#fullwidth" class="full-width pull-right btn btn-success">
          <i class="glyphicon glyphicon-resize-full"></i>
        </a>
      </div>
      <div class="panel-body">
        <div class="highcharts_horizontal_stacked"></div>
      </div>
    </div>
  </div>
</div>

这是JsFiddle Link

解决方法:

我发现window.dispatchEvent(new Event(‘resize’))是触发调整大小的方法.

$('.full-width').click(function () {
  $(this).parents('[class^="col"]').toggleClass('full-width-box');
  window.dispatchEvent(new Event('resize'));
});

演示http://www.codeply.com/go/qY1TSQOZ0r

附: – 您不需要其他单击/调整大小功能

上一篇:Mysql使用Trigger创建表


下一篇:Postman接口测试之POST、GET请求方法