Easyui 让Window弹出居中与最大化后居中
生活随笔
收集整理的這篇文章主要介紹了
Easyui 让Window弹出居中与最大化后居中
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
easyui1.3.2版本,window的彈出不會居中了。而dialog是會居中的,我們必須為為window的open事件做擴展
代碼如下:只要加入以下代碼即可.如果你是看了MVC項目系列的,把他放到jquery.easyui.plus.js里面就可以了
//讓window居中 var easyuiPanelOnOpen = function (left, top) {var iframeWidth = $(this).parent().parent().width();var iframeHeight = $(this).parent().parent().height();var windowWidth = $(this).parent().width();var windowHeight = $(this).parent().height();var setWidth = (iframeWidth - windowWidth) / 2;var setHeight = (iframeHeight - windowHeight) / 2;$(this).parent().css({/* 修正面板位置 */left: setWidth,top: setHeight});if (iframeHeight < windowHeight){$(this).parent().css({/* 修正面板位置 */left: setWidth,top: 0});}$(".window-shadow").hide(); }; $.fn.window.defaults.onOpen = easyuiPanelOnOpen;
完美居中。
點擊最大化后,再次最小化時也會出現不居中現象,我們必須,擴展resize事件。
var easyuiPanelOnResize = function (left, top) {var iframeWidth = $(this).parent().parent().width();var iframeHeight = $(this).parent().parent().height();var windowWidth = $(this).parent().width();var windowHeight = $(this).parent().height();var setWidth = (iframeWidth - windowWidth) / 2;var setHeight = (iframeHeight - windowHeight) / 2;$(this).parent().css({/* 修正面板位置 */left: setWidth-6,top: setHeight-6});if (iframeHeight < windowHeight) {$(this).parent().css({/* 修正面板位置 */left: setWidth,top: 0});}$(".window-shadow").hide();//$(".window-mask").hide().width(1).height(3000).show(); }; $.fn.window.defaults.onResize = easyuiPanelOnResize;
window組件可以兼容了
轉載于:https://www.cnblogs.com/ymnets/p/3439302.html
總結
以上是生活随笔為你收集整理的Easyui 让Window弹出居中与最大化后居中的全部內容,希望文章能夠幫你解決所遇到的問題。