解决easyDialog弹出框加载延时图片的时候不居中问题

来源:互联网 发布:搜狗拼音去广告优化版 编辑:程序博客网 时间:2024/06/06 19:00

原理:监视弹窗内容加载完成,自动改变弹窗定位(初始没内容的时候弹窗的宽高和有内容的时候宽高是不一样的,当内容加载后,其宽度、高度被改变,通过比较两次的宽高的,重新定位弹出框)。

在open方法的末尾、Dialog.data上面添加以下代码即可:

var IntervalTimer = setInterval(function() {    if (dialogWrap.offsetWidth != eWidth) {        eWidth = dialogWrap.offsetWidth;        eHeight = dialogWrap.offsetHeight;        widthOverflow = eWidth > docWidth;        heigthOverflow = eHeight > docHeight;        // 居中定位        if (!options.follow) {            dialogBox.style.marginLeft = '-' + (widthOverflow ? docWidth / 2 : eWidth / 2) + 'px';            dialogBox.style.marginTop = '-' + (heigthOverflow ? docHeight / 2 : eHeight / 2) + 'px';        } else {            dialogBox.style.marginLeft = dialogBox.style.marginTop = '0px';        }        // 防止select穿透固定宽度和高度        if (isIE6 && !options.overlay) {            dialogBox.style.width = eWidth + 'px';            dialogBox.style.height = eHeight + 'px';        }        clearInterval(IntervalTimer);    }})

大概位置如图:


1 0
原创粉丝点击