1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
function _makeExpandingArea(el) {
var timer = null;
//由于ie8有溢出堆栈问题,故调整了这里
var setStyle = function (el, auto) {
if (auto) el.style.height = 'auto';
el.style.height = el.scrollHeight + 'px';
}
var delayedResize = function (el) {
if (timer) {
clearTimeout(timer);
timer = null;
}
timer = setTimeout(function () {
setStyle(el)
}, 200);
}
if (el.addEventListener) {
el.addEventListener('input', function () {
setStyle(el, 1);
}, false);
setStyle(el)
} else if (el.attachEvent) {
el.attachEvent('onpropertychange', function () {
setStyle(el)
})
setStyle(el)
}
if (window.VBArray && window.addEventListener) { //IE9
el.attachEvent("onkeydown", function () {
var key = window.event.keyCode;
if (key == 8 || key == 46) delayedResize(el);
});
el.attachEvent("oncut", function () {
delayedResize(el);
}); //处理粘贴
}
}
React.useEffect(() => {
//这里用了 jquery 来获取元素
let dom = $('.mde-text:first')
Debug(dom, 'mdEditor')
console.log(dom)
//注册事件
_makeExpandingArea(dom[0])
}, [])
|