自定义弹出框

 1     function showDialog(){
 2             var $by = $(window),
 3                 obj = $('.dialog'),
 4                 brsW = $by.width(),
 5                 brsH = $by.height(),
 6                 sclL = $by.scrollLeft(),
 7                 sclT = $by.scrollTop(),
 8                 curW = obj.width(),
 9                 curH = obj.height();
10             //计算对话框居中时的左、上边距
11             var left = sclL + (brsW - curW)/2;
12             var top = sclT + (brsH - curH)/2;
13             //设置对话框的位置
14             obj.css({"left":left,"top":top});
15             console.log(sclT,sclL)
16         }
17         showDialog();
18         $(window).resize(function(){
19             showDialog();
20         })
1 .dialog{
2     width: 500px;
3     height: 500px;
4     border: 1px solid #ddd;
5     position: absolute;
6 }

 

posted @ 2016-12-07 13:45  蛋Mrs炒饭  阅读(176)  评论(0编辑  收藏  举报