| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- function initWdDragWidth(offsetheight, topNum) {
- linewidth(offsetheight);
- }
- //初始化拖动线
- function linewidth(offsetheight) {
-
- function getAttr(wdDragWidth, name) {
- /* 改,增加 {} 后,导致 第一个(min) 拿不到 -- "{min:300,max:1490,right:true}"。Lin
- var reg = new RegExp("(^|,)" + name + ":([^,]*)");
- */ var reg = new RegExp("(^{|,)" + name + ":([^,]*)");
- var r = wdDragWidth.match(reg);
- if(r != null) return unescape(r[2]);
- return null;
- }
-
- var dw = {};
- var wdDragWidthAry = $("[ssDragw]"); // = $("[wdDragWidth]")。Lin
- if(wdDragWidthAry.length!=2)return;1
-
- var leftSide=true;//拖动手柄的方向
- for(var i = 0; i < wdDragWidthAry.length; i++) {
- var wdDragWidth = $(wdDragWidthAry[i]).attr("ssDragw"); // ("wdDragWidth")。Lin
- /* 改,side:right 改为 right:true -- 只写 right:true,不写 right:false。Lin
- if(wdDragWidth.indexOf("side")>0){
- leftSide=("left"==getAttr(wdDragWidth, "side"))?true:false;
- }
- */ leftSide = wdDragWidth.indexOf("right") < 0;
- if(i==1) {
- dw.domB = $(wdDragWidthAry[i]);
- }else {
- dw.domAWidth = $(wdDragWidthAry[i]).width();
- dw.domA = $(wdDragWidthAry[i]);
- var max =wdDragWidth.indexOf("max")>-1? getAttr(wdDragWidth, "max").replace("px"):0;
- var min =wdDragWidth.indexOf("min")>-1? getAttr(wdDragWidth, "min").replace("px"):0;
- dw.maxWidth = parseInt(max);
- dw.minWidth = parseInt(min);
- }
- }
- if(dw.domA){
- $("#dragIcon").remove();
- dw.dragDom=$('<div id="dragIcon" class="'+(leftSide?'content-vSeperator-left':'content-vSeperator')+'"><span></span></div>');
- //dw.dragDom=$("<div id=\"dragIcon\" style='width: 12px;height: 518px;background: red;float: left;cursor: w-resize;'></div>");
- dw.domA.after(dw.dragDom);
- $("<div id=\"dragwidthmask\" style=\"left:0px;top:0px;z-index: 999;display: none;position: absolute;\"></div>").css({width:$(window).width(),height:$(window).height()}).appendTo("body");
- }
-
- // dw.countWidth = $(dw.domA).width() + $(dw.domB).width();
- dw.x = 0; // 鼠标按下时光标的X值
- dw.w = 0; // 拖拽前div的宽
-
- $(dw.dragDom)[0].onmousedown = function(ev) {
- if(!dw.countWidth){
- dw.countWidth = $(dw.domA).width() + $(dw.domB).width();
-
- }
-
-
- var ev = ev || window.event;
- dw.x = ev.clientX; // 获取鼠标按下时光标x的值
- dw.w = $(dw.domA).width(); // 拖动前的宽度
- $("#dragwidthmask").show();
-
-
-
- function dragmoveEnd(){
- document.onmousemove = null;
- document.onmouseup = null;
- $("#dragwidthmask").hide();
- }
-
- var mousemoveid=null;
- document.onmousemove = function(ev) {
- if(mousemoveid){
- clearTimeout(mousemoveid)
- mousemoveid=null;
- }
- mousemoveid=setTimeout(dragmoveEnd,3000);
-
- var ev = ev || window.event;
- var W = ev.clientX - dw.x + dw.w;
- if(W < dw.minWidth) {
- W = dw.minWidth;
- }else if(W > dw.maxWidth){
- W = dw.maxWidth;
- }
- $(dw.domA).width(W + 'px');
- $(dw.domB).width((dw.countWidth - W) + 'px');
- }
-
-
- document.onmouseup = function() {
- dragmoveEnd()
- }
- return false;
- }
- $(dw.dragDom)[0].ondblclick = function() {
- // 如果当前是最小状态,则直接恢复最大宽度
- // if($(dw.domA).width() <= dw.minWidth) {
- // $(dw.domA).width(dw.maxWidth);
- // $(dw.domB).width(dw.countWidth - dw.maxWidth);
- // return;
- //}
- $(dw.domA).width(dw.domAWidth + "px");
- $(dw.domB).width((dw.countWidth - dw.domAWidth) + "px");
- }
-
-
-
-
-
- }
|