窗口和对话框居中对齐

Web前端的窗口,对话框等界面,经常需要居中对齐。
在Jquery Easyui中等window组件中,通常有宽度width、高度height、距离容器左边的距离left、距离容器顶部的距离top,4个参数。


在实现过程中,主要就是动态或静态设置这4个参数。


当前窗口的高度:$(window).width()
当前窗口的宽度:$(window).width()


如果是获得父窗口的,用window.parent就可以了。


width:是个方法,不是属性。


下面是一个例子:
 var windowWidth =$(window.parent).width();
    var windowHeight=$(window.parent).height();
    var width=380;
    var height=windowHeight-200;
    var top=(windowHeight-height)/2;
    var left=(windowWidth-width)/2;
    var $win = $('#preView').window({
      content : '<iframe scrolling="yes" frameborder="0"  src="'  
              + href  
              + '" style="100%;height:98%;"></iframe>',  
        title: 'APP预览',
        width,
        height: height,
        top: top,
        left: left,
    });


    $win.window('open');

宽度:固定宽度380
高度:窗口高度-固定200
距离顶部的距离:(窗口高度-对话框的高度)/2,居中对齐
距离左边的距离:居中对齐


在2种屏幕,试了,没有问题~
原文地址:https://www.cnblogs.com/qitian1/p/6462615.html