項目開發經驗分享—漂亮的彈出框效果,項目開發經驗分享

來源:互聯網
上載者:User

項目開發經驗分享—漂亮的彈出框效果,項目開發經驗分享

    上一篇部落格我們分享了動態載入頁面經驗《分頁查詢》。今天我們來分享一下UI設計經驗:漂亮的彈出框效果!

引言    大家在使用軟體的時候應該有看到過這樣的彈出框(如),通過雙擊就可以達到選擇的效果,可以單選,可以全部選擇,比起我們常用的一個一個勾選的方式,不僅樣式漂亮,還更方便:             所以當我們的項目遇到類似的功能時,比如,給不同的課程類型指定模板,可以單個指定,也可以全部指定,同時也要方便取消單個(或全部)指定,這時,我們就可以借鑒提供這樣的功能,給使用者更高的體驗度!下面我們來看看具體的實現吧:

思路

1、根據需求設計UI樣式

2、通過js代碼實現效果

實現

1.根據需求設計UI樣式,布局:

<body><div id="openClassType" class="easyui-window"  title="添加課程類型" data-options="modal:true,closed:true,maximizable:false,minimizable:false,conCls:'icon-save'" style="width: 430px; height: 480px; padding: 10px;" >  <div title="模版名稱">模板名稱:<input class="easyui-combobox"  id="template" name="template" style="width:150px"data-options="url:'queryTemplate',method:'get',valueField:'id',textField:'templateName',panelHeight:'auto',panelWidth:'150px'"></div><div>_______________________________________________<br><br>  待選課程類型:                               已選課程類型: <br>                                                                                     </div> <table style="width:100%;padding:5px;" border="0" cellpadding="0" cellspacing="0" >  <tr>    <td>          <select multiple="multiple" id="select1" style="width:150px;height:300px; float:left; ">            <option value="專業選修課實踐">專業選修課實踐</option>            <option value="專業選修課理論">專業選修課理論</option>            <option value="公用課實踐">公用課實踐</option>            <option value="公用課理論">公用課理論</option>            <option value="專業必修課實踐">專業必修課實踐</option>            <option value="專業必修課理論">專業必修課理論</option>            <option value="公用必修課理論">公用必修課理論</option>            <option value="公用必修課實踐">公用必修課實踐</option>            <option value="公用選修課理論">公用選修課理論</option>            <option value="公用選修課實踐">公用選修課實踐</option>                   </select>               <div style="float:left" style=" padding:20px; margin-top:20px;" >            <span id="add1" style="width: 420px; height: 480px; padding:10px;" hidden="true" >  <a type="button" class="easyui-linkbutton" value=">" data-options="iconCls:'icon-redo'" >添加</a>  </span><br />    <span id="add2" style="width: 420px; height: 480px; padding:10px;"hidden="true" >  <a type="button" class="easyui-linkbutton" value=">" data-options="iconCls:'icon-redo'" >添加</a>  </span><br />    <span id="add3" style="width: 420px; height: 480px; padding:10px;"hidden="true" >  <a type="button" class="easyui-linkbutton" value=">" data-options="iconCls:'icon-redo'" >添加</a>  </span><br />          <span id="add" style="width: 420px; height: 480px; padding:10px;" >  <a type="button" class="easyui-linkbutton" value=">" data-options="iconCls:'icon-redo'" >添加</a>  </span><br />            <span id="add_all" style=" padding:10px;">          <a type="button" class="easyui-linkbutton" value=">>" data-options="iconCls:'icon-ok'">全選</a>  </span> <br />            <span id="remove" style="width: 420px; height: 480px; padding:10px; ">  <a type="button" class="easyui-linkbutton" value="<" data-options="iconCls:'icon-undo'">刪除</a>             </span><br />                    <span id="remove_all" style="width: 420px; height: 480px; padding:10px;">          <a type="button" class="easyui-linkbutton" value="<<" data-options="iconCls:'icon-cancel'">全刪</a>            </span> <br />            <span id="move_top" style="width: 420px; height: 480px; padding:10px;">  <a type="button"  value="↑" class="easyui-linkbutton" data-options="iconCls:'icon-add'" >向上</a>  </span><br />    <span id="move_mutton" style="width: 420px; height: 480px; padding:10px;">  <a type="button" class="easyui-linkbutton" value="↓" data-options="iconCls:'icon-remove'">向下</a>  </span><br />  <span id="top" style="width: 420px; height: 480px; padding:10px;" hidden="true"><input type="button" class="easyui-linkbutton" data-options="iconCls:'icon-add'" value="置於頂部" /></span><br /><span id="buttom" style="width: 420px; height: 480px; padding:10px;"hidden="true"> <input type="button" class="easyui-linkbutton" data-options="iconCls:'icon-add'" value="置於底部"/><a href="###"></a></span></div>        <div>          <select multiple="multiple" id="select2" style="width: 150px;height:300px; float:lfet; " >          </select>        </div>      </div></td>  </tr></table>  <div id="addone-buttons" style="width: 160px; margin-left: 110px;"><a href="javascript:void(0)" class="easyui-linkbutton c6"  onclick="saveTemplate()" style="width: 60px">確定</a>      <a href="javascript:void(0)" class="easyui-linkbutton"   onclick="javascript:$('#openClassType').window('close')" style="width: 60px">取消</a></div>    </div></body>
2、通過js代碼實現添加、全選、刪除、全刪等功能

<script type="text/javascript"> //添加課程類型資訊function saveTemplate() { $('#fm').form('submit',{success:function(data){$('#fm').form('clear');$('#addone').window('close');                $('#dg').datagrid("reload");                                $.messager.alert('提示','添加成功');},error:function(data){   alert("添加失敗");  }});  $('#openClassType').window('close')}//下拉框交換JQuery$(function(){    //移到右邊    $('#add').click(function() {    //擷取選中的選項,刪除並追加給對方        $('#select1 option:selected').appendTo('#select2');    });    //移到左邊    $('#remove').click(function() {        $('#select2 option:selected').appendTo('#select1');    });    //全部移到右邊    $('#add_all').click(function() {        //擷取全部的選項,刪除並追加給對方        $('#select1 option').appendTo('#select2');    });    //全部移到左邊    $('#remove_all').click(function() {        $('#select2 option').appendTo('#select1');    });    //雙擊選項    $('#select1').dblclick(function(){ //綁定雙擊事件        //擷取全部的選項,刪除並追加給對方        $("option:selected",this).appendTo('#select2'); //追加給對方    });    //雙擊選項    $('#select2').dblclick(function(){       $("option:selected",this).appendTo('#select1');    });      //上移一行        $("#move_top").click(function(){if(null == $('#select2').val()){ alert('請選擇一項'); return false; }             var selected = $("#select2 option:selected");            if(selected.get(0).index!=0){                selected.each(function(){                    $(this).prev().before($(this));                });            }        });     //下移一行        $("#move_mutton").click(function(){if(null == $('#select2').val()){ alert('請選擇一項'); return false; }             var allOpts = $("#select2 option");            var selected = $("#select2 option:selected");            if(selected.get(selected.length-1).index!=allOpts.length-1){                for(i=selected.length-1;i>=0;i--){                   var item = $(selected.get(i));                   item.insertAfter(item.next());                }            }        });    //移至底部        $("#buttom").click(function(){if(null == $('#select2').val()){ alert('請選擇一項'); return false; }             var allOpts = $("#select2 option");            var selected = $("#select2 option:selected");            if(selected.get(selected.length-1).index!=allOpts.length-1){                for(i=selected.length-1;i>=0;i--){                   var item = $(selected.get(i));                                                                        var buttom = $(allOpts.get(length-1));                   item.insertAfter(buttom);                }            }    });  //移至頂部        $("#top").click(function(){if(null == $('#select2').val()){ alert('請選擇一項'); return false; }             var allOpts = $("#select2 option");            var selected = $("#select2 option:selected");            if(selected.get(0).index!=0){                for(i=0;i<selected.length;i++){                   var item = $(selected.get(i));                   var top = $(allOpts.get(0));                   item.insertBefore(top);                }            }        });});//向上移動function moveUp(selectObj){    var theObjOptions=selectObj.options;//最上面的一個不需要移動,所以直接從i=1開始    for(var i=1;i<theObjOptions.length;i++) {        if( theObjOptions[i].selected && !theObjOptions[i-1].selected ) {            swapOptionProperties(theObjOptions[i],theObjOptions[i-1]);        }    }}//向下移動function moveDown(selectObj){    var theObjOptions=selectObj.options;//向下移動,最後一個不需要處理,所以直接從倒數第二個開始     for(var i=theObjOptions.length-2;i>-1;i--) {        if( theObjOptions[i].selected && !theObjOptions[i+1].selected ) {            swapOptionProperties(theObjOptions[i],theObjOptions[i+1]);        }    }}//操作向下向上移動function swapOptionProperties(option1,option2){//交換三部曲     var tempStr=option1.value;//option1賦值給tempStr    option1.value=option2.value;//交換,option2賦值給option1    option2.value=tempStr;//交換,tempValSource賦值給tempStrvar tempValSource=option1.valSource;//option1賦值給tempValSourceoption1.valSource=option2.valSource;//交換,option2賦值給option1option2.valSource=tempValSource;//交換,tempValSource賦值給option2//擷取值    tempStr=option1.text;     option1.text=option2.text;    option2.text=tempStr;    tempStr=option1.selected;    option1.selected=option2.selected;    option2.selected=tempStr;}function onrightClick() {                var selected = $('#select2').text();alert(selected);            }function onleftClick(){var selected =$("#select1").text(); alert(selected);}</script>

效果

總結

    從使用者角度出發,以使用者為主,越靠近使用者的使用習慣,軟體親和力越高,開發的軟體越受歡迎!


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.