/** * Created by JetBrains WebStorm. * User: xudaiquan * Date: 12-12-26 * Time: 涓嬪崍6:56 * To change this template use File | Settings | File Templates. */ /*** * 关闭弹出框 * shadowId 阴影层div的id * dialogId 弹出层div的id * */ function closeDialog(shadowId,dialogId){ $('#'+shadowId).hide(); $('#'+dialogId).hide(); } /*** * 打开弹出框 * shadowId 阴影层div的id * dialogId 弹出层div的id * */ function openDialog(shadowId,dialogId){ var theHeight = $(document).height(); var theWidth = $(document).width(); var obj = $('#'+dialogId); var screenWidth = $(window).width(); var screenHeight = $(window).height(); var scrolltop = $(document).scrollTop(); var scrollLeft = $(document).scrollLeft(); var objLeft = (screenWidth - obj.width()) / 2 + scrollLeft; var objTop = (screenHeight - obj.height()) / 2 + scrolltop; $('#'+shadowId).css('height',theHeight+scrolltop).css('width',theWidth+scrollLeft).show(); $('#'+dialogId).css({'top':objTop,'left':objLeft}).show(); //浏览器窗口大小改变时 $(window).resize(function() { screenWidth = $(window).width(); screenHeight = $(window).height(); scrolltop = $(document).scrollTop(); objLeft = (screenWidth - obj.width()) / 2 + scrollLeft; objTop = (screenHeight - obj.height()) / 2 + scrolltop; $('#'+shadowId).css('height',theHeight+scrolltop); $('#'+dialogId).css({'top':objTop,'left':objLeft}); }); //浏览器有滚动条时的操作 $(window).scroll(function() { screenWidth = $(window).width(); screenHeight = $(window).height(); scrolltop = $(document).scrollTop(); var scrollLeft = $(document).scrollLeft(); objLeft = (screenWidth - obj.width()) / 2 + scrollLeft; objTop = (screenHeight - obj.height()) / 2 + scrolltop; $('#'+dialogId).css({'top':objTop,'left':objLeft}); }); }