easyui視窗(window)越界問題--限定easyui視窗(window)活動範圍,視窗easyui

來源:互聯網
上載者:User

easyui視窗(window)越界問題--限定easyui視窗(window)活動範圍,視窗easyui

在使用easyui視窗(window)時遇到一個問題,在表單拖拽或改變大小時,如果超出瀏覽器範圍,就回不來了.

因為瀏覽器不會顯示捲軸.還要重新重新整理頁面.

於是我寫了一個方法來實現限定表單的活動範圍(只能顯示在瀏覽器可視範圍中):


<div id="createSchoolWindow" class="easyui-window" title="建立學校"
        data-options="modal:true,closed:true,minimizable:false,iconCls:'icon-add'"
        style="width: 530px; height: 380px; padding: 10px;">
        <form id="createSchoolForm" method="post">
            <table>
                <tr>
                    <td>學校名稱:</td>
                    <td><input class="easyui-validatebox" type="text" name="name" data-options="required:true"></input></td>
                    <td>學校網址:</td>
                    <td><input class="easyui-validatebox"  type="text" name="webSite"  data-options="validType:'url'"/></input></td>
                </tr>
                <tr>
                    <td>連絡人姓名:</td>
                    <td><input class="easyui-validatebox" type="text" name="linkman"></input></td>
                    <td>連絡人電話:</td>
                    <td><input class="easyui-validatebox" type="text" name="linkmanPhone"></input></td>
                </tr>
                <tr>
                    <td>學校地址:</td>
                    <td colspan="3"><textarea rows="4" cols="25" name="addr"></textarea></td>
                </tr>
                <tr>
                    <td>備忘:</td>
                    <td colspan="3">
                    <textarea rows="4" cols="25" name="remark"></textarea>
                    </td>
                </tr>
                <tr>
                    <td colspan="4" align="center">
                        <a href="#" class="easyui-linkbutton" onclick="createSchool();" icon="icon-save">儲存</a>
                        <a href="#" class="easyui-linkbutton" onclick="closeCreateSchoolWindow();" icon="icon-cancel">關閉</a>
                    </td>
                </tr>
            </table>
        </form>
    </div>


/*

原理很簡單:註冊onMove和onResize事件,在越界是自動回複:

*/

$(document).ready(function() {
   
    
    $("#createSchoolWindow").window({
        onMove:function(left,top){
            //console.log(this.left+" - "+top);
            if(left<0){
                $("#createSchoolWindow").window("resize",{left:0});
            }
            if(top<0){
                $("#createSchoolWindow").window("resize",{top:0});
            }
        },
        onResize:function(width, height){
            var w=$(window).width();//可視寬度
            var h=$(window).height();//可視高度
            var left=$("#createSchoolWindow").window("options").left;//表單左邊距離
            var top=$("#createSchoolWindow").window("options").top;//表單右邊距離
            if((width+left)>w){
                $("#createSchoolWindow").window("resize",{width:w-left});
            }
            if((height+top)>h){
                $("#createSchoolWindow").window("resize",{height:h-top});
            }
        }
    });
    
});


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.