‘liusuyi’
2023-08-09 161b9318e345c8a0c9cdc133b33a1c759495f323
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
49
50
51
52
53
54
55
56
57
var index = (function (element, listener) {
    var expand = document.createElement('_');
    var shrink = expand.appendChild(document.createElement('_'));
    var expandChild = expand.appendChild(document.createElement('_'));
    var shrinkChild = shrink.appendChild(document.createElement('_'));
 
    var lastWidth = void 0,
        lastHeight = void 0;
 
    shrink.style.cssText = expand.style.cssText = 'height:100%;left:0;opacity:0;overflow:hidden;pointer-events:none;position:absolute;top:0;transition:0s;width:100%;z-index:-1';
    shrinkChild.style.cssText = expandChild.style.cssText = 'display:block;height:100%;transition:0s;width:100%';
    shrinkChild.style.width = shrinkChild.style.height = '200%';
 
    element.appendChild(expand);
 
    test();
 
    return stop;
 
    function test() {
        unbind();
 
        var width = element.offsetWidth;
        var height = element.offsetHeight;
 
        if (width !== lastWidth || height !== lastHeight) {
            lastWidth = width;
            lastHeight = height;
 
            expandChild.style.width = width * 2 + 'px';
            expandChild.style.height = height * 2 + 'px';
 
            expand.scrollLeft = expand.scrollWidth;
            expand.scrollTop = expand.scrollHeight;
            shrink.scrollLeft = shrink.scrollWidth;
            shrink.scrollTop = shrink.scrollHeight;
 
            listener({ width: width, height: height });
        }
 
        shrink.addEventListener('scroll', test);
        expand.addEventListener('scroll', test);
    }
 
    function unbind() {
        shrink.removeEventListener('scroll', test);
        expand.removeEventListener('scroll', test);
    }
 
    function stop() {
        unbind();
 
        element.removeChild(expand);
    }
});
 
module.exports = index;