/**
 * listenCssRender.js
 *
 * @Author: apple
 * @Date: 2018/3/9 10:32
 */

/**
 * 1.创建一个div
 * 2.给div增加一个样式高度
 * 3.判断当前div的高度是否等于设定高度
 * 4.根据结果判断是否加载css完毕
 * */
import judgeBroswer from './judgeBroswer';
var listenCssRender = function listenCssRender(cb) {
    var div = document.createElement('div');
    document.body.appendChild(div);
    // div.style.height = '1px';
    var randomCls = Math.floor(Math.random() * 10000);
    div.classList.add('ne-util-css-render-1px');
    div.id = 'id' + randomCls;
    var timer = setInterval(function () {
        if (div) {
            var height = div.getBoundingClientRect().height;
            var removeTarget = function removeTarget() {
                clearInterval(timer);
                var targetNode = document.querySelector('#id' + randomCls);
                if (judgeBroswer.isIE() || judgeBroswer.isIE11()) {
                    targetNode.removeNode(true);
                } else {
                    targetNode.remove();
                }
            };
            if (height === 1) {
                removeTarget();
                cb && cb();
            }
        } else {
            clearInterval(timer);
        }
    }, 16.7);
};

export default listenCssRender;