enhsplitle.js是一个功能丰富的jQuery插件,用于创建可拖动的拆分器(也称为拆分布局或拆分视图)来分离网页上的内容。
使用此插件,您可以水平或垂直拆分页面上的任何内容区域,用户可以拖动拆分器来调整相邻内容区域的大小。可以在各种web应用程序中使用,以创建拆分视图、可调整大小的窗格和复杂的框架。
1.要开始,请在网页上包含jQuery enhsplite.js。
- <!-- jQuery is required -->
- <script src="/path/to/cdn/jquery.slim.min.js"></script>
- <!-- enhsplitter.js plugin -->
- <script src="js/jquery.enhsplitter.js"></script>
- <link href="css/jquery.enhsplitter.css" rel="stylesheet"/>
2.初始化插件,在两个DIV元素之间插入一个可拖动的拆分器,如下所示:
- <div id="panels">
- <div>
- Pane 1
- </div>
- <div>
- Pane 2
- </div>
- </div>
- $(function(){
- $('#panels').enhsplitter();
- });
3.可用于自定义拆分器的选项。
{位置:125}
,或后缀为“px”的字符串{位置:'125px'}
,或以百分比形式表示,作为后缀为“%”的字符串。{职位:“25%”}
不带后缀的字符串将被假定为以像素为单位。'默认'
目前相当于“条纹”,但未来可能会发生变化。'条纹'
绘制一个带条纹的句柄,如上面的前两个示例所示bar’绘制一个狭窄的灰色条,如上面的第三个示例所示。“块”
绘制一个宽的灰色块,填充拆分器的宽度。“点”
画五个等距的小圆点,没有边界。“许多点”
画一系列小点。“无”
完全隐藏手柄,使其禁用。设置时也可以实现此效果{不可见:true};
不需要同时设置这两者。<用户定义>
-您创建的任何CSS类的标识符。通过添加新的.splitter句柄类(请参阅CSS文件),您可以创建自定义样式,而无需覆盖标准样式。{不可见:true}
,也有助于增加移动站点上的拆分器大小(以便在触摸设备上更容易使用)。可以使用任何CSS值;没有后缀的数字将被视为像素值。
- $('#panels').enhsplitter({
- vertical: true,
- position: '50%',
- leftMinSize: 100,
- leftMaxSize: null,
- rightMinSize: 100,
- rightMaxSize: null,
- invisible: false,
- handle: 'default',
- fixed: false,
- collapse: 'left',
- height: null,
- splitterSize: null,
- onDragStart: function (event, splitter_container) { ... },
- onDragEnd: function (event, splitter_container) { ... },
- onDrag: function (event, splitter_container) { ... },
- });
- $(function(){
- $('#panels').enhsplitter();
- });
4.API方法。
- // Changes the splitter position to the location specified (with range checks).
- $('#panels').enhsplitter('move', [number (px)|string (px|%)])
- // Forces a refresh of the container size and splitter location (with range checks).
- $('#panels').enhsplitter('refresh')
- // Resets the splitter location to it's starting position.
- $('#panels').enhsplitter('reset')
- // Collapses the splitter as if the collapse handle was clicked.
- $('#panels').enhsplitter('collapse')
- // Returns the splitter to it's pre-collapsed position.
- $('#panels').enhsplitter('uncollapse')
- // Sets whether the splitter is visible or not. This is equivalent to (but opposite from) the invisible option, visually hiding the splitter but leaving it usable.
- $('#panels').enhsplitter('visible', [true|false])
- // Equivalent to the handle option, changes the handle style on the fly.
- $('#panels').enhsplitter('handle', ['default'|'bar'|'block'|'none'|<user-defined>])
- // Removes the splitter container, splitter panels, and splitter bar, returning the DOM to its previous layout.
- $('#panels').enhsplitter('destroy');