窗口和对话框居中对齐

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="width:100%;height:98%;"></iframe>',  
        title: 'APP预览',
        width: width,
        height: height,
        top: top,
        left: left,
    });


    $win.window('open');

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


在2种屏幕,试了,没有问题~

转载于:https://www.cnblogs.com/qitian1/p/6462614.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值