当前位置:网站首页>JS monitors the width and height changes of div
JS monitors the width and height changes of div
2022-06-25 12:04:00 【GIS roast lamb leg is delicious】
Preface explains
1. Monitoring will be encountered during development div The width and height of . For example, when the width and height change echarts Need to redraw .
2. Realization principle : hold div Put it in iframe in , monitor iframe Of resize event .
vue call
import {ElementResize} from '@/utils/ElementResize.js
// Create a listening instance
var eleResize = new ElementResize('#content');
eleResize.listen(function() {
console.log(' monitor ')
})
monitor ElementResize.js file
/**
* Element width height monitoring
* @param {Object} el Listen for element selectors
*/
function ElementResize(eleSelector) {
if (!(this instanceof ElementResize)) return;
if (!eleSelector) return;
this.eleSelector = eleSelector;
this.el = document.querySelector(eleSelector);
this.queue = [];
this.__init(); //globel init
}
// initialization
ElementResize.prototype.__init = function() {
let iframe = this.crateIElement();
this.el.style.position = 'relative';
this.el.appendChild(iframe)
this.bindEvent(iframe.contentWindow);
}
/**
* Set element style
* @param {HTMLObject} el
* @param {Object} styleJson
*/
ElementResize.prototype.setStyle = function(el, styleJson) {
if (!el) return;
styleJson = styleJson || {
opacity: 0,
'z-index': '-1111',
position: 'absolute',
left: 0,
top: 0,
width: '100%',
height: '100%',
};
let styleText = '';
for (var key in styleJson) {
styleText += (key + ':' + styleJson[key] + ';');
}
el.style.cssText = styleText;
}
/**
* Create elements
* @param {Object} style
*/
ElementResize.prototype.crateIElement = function(style) {
let iframe = document.createElement('iframe');
this.setStyle(iframe);
return iframe;
}
/**
* The binding event
* @param {Object} el
*/
ElementResize.prototype.bindEvent = function(el) {
if (!el) return;
var _self = this;
el.addEventListener('resize', function() {
_self.runQueue();
}, false)
}
/**
* Run the queue
*/
ElementResize.prototype.runQueue = function() {
let queue = this.queue;
for (var i = 0; i < queue.length; i++) {
(typeof queue[i]) === 'function' && queue[i].apply(this);
}
}
/**
* External monitoring
* @param {Object} cb Callback function
*/
ElementResize.prototype.listen = function(cb) {
if (typeof cb !== 'function') throw new TypeError('cb is not a function!');
this.queue.push(cb);
}
边栏推荐
- Specific meanings of node and edge in Flink graph
- R语言使用scale函数对神经网络的输入数据进行最小最大缩放、把数据缩放到0到1之间、并划分数据集为训练集和测试集
- ThingsPanel 發布物聯網手機客戶端(多圖)
- 黑马畅购商城---3.商品管理
- ArcGIS services query filter by time field
- plt.gca()画框及打标签
- Record the process of submitting code to openharmony once
- 黑马畅购商城---1.项目介绍-环境搭建
- 2020最新最全IT学习线路
- Simple use of stream (II)
猜你喜欢

Whole process of web page request

Capacity expansion mechanism of Dict Of redis (rehash)

Windows11 MySQL service is missing

Thingspanel releases Internet of things mobile client (multiple pictures)

使用php脚本查看已开启的扩展

Sentinel integrated Nacos data source
![Caused by: org. xml. sax. SAXParseException; lineNumber: 1; columnNumber: 10; Processing matching '[xx][mm][ll]' is not allowed](/img/27/ebf13bdb16978bedbeaa5cd1d780c9.jpg)
Caused by: org. xml. sax. SAXParseException; lineNumber: 1; columnNumber: 10; Processing matching '[xx][mm][ll]' is not allowed

What should I do to dynamically add a column and button to the gird of VFP?

黑马畅购商城---1.项目介绍-环境搭建

Specific meanings of node and edge in Flink graph
随机推荐
云原生数据湖以存储、计算、数据管理等能力通过信通院评测认证
Black Horse Chang Shopping Mall - - - 3. Gestion des produits de base
Caused by: org. xml. sax. SAXParseException; lineNumber: 1; columnNumber: 10; Processing matching '[xx][mm][ll]' is not allowed
黑马畅购商城---8.微服务网关Gateway和Jwt令牌
Openfeign uses
A detour taken by a hardware engineer
Gradle知识点
Record the process of submitting code to openharmony once
.Net Core 中使用工厂模式
Le détour d'un ingénieur en matériel
R语言使用构建有序多分类逻辑回归模型、epiDisplay包的ordinal.or.display函数获取有序logistic回归模型的汇总统计信息(变量对应的优势比及其置信区间、以及假设检验的p值)
网络 | traceroute,路由跟踪命令,用于确定 IP 数据包访问目标地址所经过的路径。
Eureka accesses the console and reports an error: whitelabel error page
做自媒体视频需要怎么做才能年收入一百万?
动态代理
plt.gca()画框及打标签
Windows11 MySQL service is missing
Under what circumstances will Flink combine operator chains to form operator chains?
Data Lake survey
Cesium editing faces