博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jQuery实现spliter效果
阅读量:5894 次
发布时间:2019-06-19

本文共 6361 字,大约阅读时间需要 21 分钟。

hot3.png

jQuery实现spliter效果
jQuery splitter demo

This pane limited to a range of 100 to 300 pixels wide with the minAsize / maxAsize properties of the plugin..

 

Toolbar?

testing

testing

testing

testing

some content

some content

some content

some content

some content

some content

splitter.js文件
/** jQuery.splitter.js - animated splitter plugin** version 1.0 (2010/01/02) * * Dual licensed under the MIT and GPL licenses: *   http://www.opensource.org/licenses/mit-license.php *   http://www.gnu.org/licenses/gpl.html *//*** jQuery.splitter() plugin implements a two-pane resizable animated window, using existing DIV elements for layout.* For more details and demo visit: http://krikus.com/js/splitter** @example $("#splitterContainer").splitter({splitVertical:true,A:$('#leftPane'),B:$('#rightPane'),closeableto:0});* @desc Create a vertical splitter with toggle button** @example $("#splitterContainer").splitter({minAsize:100,maxAsize:300,splitVertical:true,A:$('#leftPane'),B:$('#rightPane'),slave:$("#rightSplitterContainer"),closeableto:0});* @desc Create a vertical splitter with toggle button, with minimum and maximum width for plane A and bind resize event to the slave element** @name splitter* @type jQuery* @param Object options Options for the splitter ( required)* @cat Plugins/Splitter* @return jQuery* @author Kristaps Kukurs (contact@krikus.com)*/ ;(function($){	$.fn.splitter = function(args){		args = args || {};		return this.each(function() {			var _ghost;		//splitbar  ghosted element 			var splitPos;	 // current splitting position			var _splitPos;	 // saved splitting position			var _initPos;	//initial mouse position			var _ismovingNow=false;	// animaton state flag			// Default opts			var direction = (args.splitHorizontal? 'h':'v');			var opts = $.extend({			minAsize:0, //minimum width/height in PX of the first (A) div.			maxAsize:0, //maximum width/height  in PX of the first (A) div.			minBsize:0, //minimum width/height in PX of the second (B) div.			maxBsize:0, //maximum width/height  in PX of the second (B) div.			ghostClass: 'working',// class name for _ghosted splitter and hovered button			invertClass: 'invert',//class name for invert splitter button			animSpeed: 250 //animation speed in ms			},{			v:{ // Vertical			moving:"left",sizing: "width", eventPos: "pageX",splitbarClass:"splitbarV",buttonClass: "splitbuttonV", cursor: "e-resize"			},			h: { // Horizontal 			moving:"top",sizing: "height", eventPos: "pageY",splitbarClass:"splitbarH",buttonClass: "splitbuttonH",  cursor: "n-resize"			}			}[direction], args);			//setup elements			var splitter = $(this);			var mychilds =splitter.children(); //$(">*", splitter[0]);			var A = args.A;	// left/top frame			var B = args.B;// right/bottom frame			var slave=args.slave;//optional, elemt forced to receive resize event//Create splitbar var C=$('
');A.after(C);C.attr({"class": opts.splitbarClass,unselectable:"on"}).css({"cursor":opts.cursor,"user-select": "none", "-webkit-user-select": "none","-khtml-user-select": "none", "-moz-user-select": "none"}).bind("mousedown", startDrag); if(opts.closeableto!=undefined){var Bt=$('
').css("cursor",'pointer');C.append(Bt);Bt.attr({"class": opts.buttonClass, unselectable: "on"});Bt.hover(function(){$(this).addClass(opts.ghostClass);},function(){$(this).removeClass(opts.ghostClass);});Bt.mousedown(function(e){if(e.target != this)return;Bt.toggleClass(opts.invertClass).hide();splitTo((splitPos==opts.closeableto)?_splitPos:opts.closeableto,true);return false;});} //reset size to default. var perc=(((C.position()[opts.moving]-splitter.offset()[opts.moving])/splitter[opts.sizing]())*100).toFixed(1);splitTo(perc,false,true); // resize event handlers;splitter.bind("resize",function(e, size){if(e.target!=this)return;splitTo(splitPos,false,true);});$(window).bind("resize",function(){splitTo(splitPos,false,true);});//C.onmousedown=startDrag function startDrag(e) { if(e.target != this)return; _ghost = _ghost || C.clone(false).insertAfter(A); splitter._initPos=C.position(); splitter._initPos[opts.moving]-=C[opts.sizing]();_ghost.addClass(opts.ghostClass).css('position','absolute').css('z-index','250').css("-webkit-user-select", "none").width(C.width()).height(C.height()).css(opts.moving,splitter._initPos[opts.moving]);mychilds.css("-webkit-user-select", "none"); // Safari selects A/B text on a moveA._posSplit = e[opts.eventPos];$(document).bind("mousemove", performDrag).bind("mouseup", endDrag); }//document.onmousemove=performDrag function performDrag(e) { if (!_ghost||!A) return; var incr = e[opts.eventPos]-A._posSplit; _ghost.css(opts.moving, splitter._initPos[opts.moving]+incr); }//C.onmouseup=endDrag function endDrag(e){ var p=_ghost.position(); _ghost.remove(); _ghost = null; mychilds.css("-webkit-user-select", "text");// let Safari select text again $(document).unbind("mousemove", performDrag).unbind("mouseup", endDrag); var perc=(((p[opts.moving]-splitter.offset()[opts.moving])/splitter[opts.sizing]())*100).toFixed(1); splitTo(perc,(splitter._initPos[opts.moving]>p[opts.moving]),false); splitter._initPos=0; }//Perform actual splitting and animate it; function splitTo(perc,reversedorder,fast) {if(_ismovingNow||perc==undefined)return;//generally MSIE problem_ismovingNow=true;if(splitPos&&splitPos>10&&splitPos<90)//do not save accidental events _splitPos=splitPos;splitPos=perc;var barsize=C[opts.sizing]()+(2*parseInt(C.css('border-'+opts.moving+'-width')));//+ border. cehap&dirtyvar splitsize=splitter[opts.sizing]();if(opts.closeableto!=perc){var percpx=Math.max(parseInt((splitsize/100)*perc),opts.minAsize);if(opts.maxAsize)percpx=Math.min(percpx,opts.maxAsize);}else{var percpx=parseInt((splitsize/100)*perc,0);}if(opts.maxBsize){if((splitsize-percpx)>opts.maxBsize)percpx=splitsize-opts.maxBsize;}if(opts.minBsize){if((splitsize-percpx)
 

转载于:https://my.oschina.net/lgscofield/blog/471186

你可能感兴趣的文章
EditText 限制输入,自定义样式,监听输入的字符,自动换行
查看>>
常用算法计算方式
查看>>
【LAMP】在Debian系linux下安装LAMP
查看>>
Xamarin.Android多界面
查看>>
[MySQL 5.6] MySQL 5.6 group commit 性能测试及内部实现流程
查看>>
[Android Pro] Android应用性能测试之CPU和内存占用(转载)
查看>>
Linux Shell 小脚本经典收藏
查看>>
Log4Net的使用
查看>>
金刚经的40句名言
查看>>
【BZOJ】1084: [SCOI2005]最大子矩阵(DP)
查看>>
一套后台管理html模版
查看>>
安卓第八夜 玛丽莲梦露
查看>>
Sublime 脚本 配置 (lua 和 JavaScript篇)
查看>>
mysql大小写敏感与校对规则
查看>>
MongoDb Windows linux平台环境及主流编程语言驱动安装同时配置mongoDb的远程连接
查看>>
PLSQL_数据泵导入导出数据Impdp/ Expdp(概念)
查看>>
Smarty3学习笔记
查看>>
[翻译] BTSimpleRippleButton
查看>>
JSP中Session的使用
查看>>
TFS(Team Foundation Server)介绍和入门
查看>>