手动触发resize事件:
function doResize(){
setTimeout(function(){
//手动触发窗口resize事件
if(document.createEvent) {
var event = document.createEvent("HTMLEvents");
event.initEvent("resize", true, true);
window.dispatchEvent(event);
} else if(document.createEventObject) {
window.fireEvent("onresize");
}
},100);
}
需要调用时:
$scope.setLiActive = function($event,areaName) {
doResize();
}
增加resize监听事件(局部demo):
window.removeEventListener("resize",resizeReport,false);
resizeReport();
window.addEventListener("resize",resizeReport,false);
function resizeReport() {
$(window).resize(function(){
console.log('---------------------------------------------');
var headerContainer = document.getElementById('zhijia-header') - 30;
var winHeight = $(window).height();//浏览器当前窗口可视区域高度
var currentActiveNum = $scope.currentActiveNum;
var bcs = 0;
bcs = Math.ceil(currentActiveNum/2);//几行
bcs = bcs > 2 ? 2 : bcs;//bcs每个图表之间的margin
var eHeight = (winHeight - (72+62+20+21*bcs)) / (bcs <= 0 ? 1 : bcs) ;
for(var i=0;i<currentDatas.length;i++){
if(currentDatas[i]['active']){
var id = 'zhijia_'+$scope.echartObj[tabIndex0]+'_'+currentDatas[i]['id'];
var div = document.getElementById(id);
div['style']['height'] = eHeight + 'px';
if(currentActiveNum == 1){
div['style']['width'] = headerContainer.clientWidth + 'px';
}
}
}
});
}
网友评论