JQuery UI - resizable

  1. 概述  
  2. resizable插件可以让选中的元素具有改变尺寸的功能。  
  3. 官方示例地址:http://jqueryui.com/demos/resizable/  
  4.   
  5. 所有的事件回调函数都有两个参数:event和ui,浏览器自有event对象,和经过封装的ui对象  
  6. ui.helper - 表示当前被改变尺寸的元素的JQuery对象  
  7. ui.originalPosition - 表示未改变尺寸之前元素的位置{top,left}  
  8. ui.originalSize - 表示未改变尺寸之前元素的大小{width,height}  
  9. ui.position - 表示当前被改变尺寸的元素的坐标值对象{top,left}  
  10. ui.size - 表示当前被改变尺寸的元素的大小值对象{width,height}  
  11.   
  12.   
  13. ·参数(参数名 : 参数类型 : 默认值)  
  14. alsoResize : Selector, jQuery, ElementDefault : false  
  15.   当调整元素大小时,同步改变另一个(或一组)元素的大小。  
  16.   初始:$('.selector').resizable({ alsoResize: '.other' });  
  17.   获取:var alsoResize = $('.selector').resizable('option''alsoResize');  
  18.   设置:$('.selector').resizable('option''alsoResize''.other');  
  19.   
  20. animate : Boolean : false  
  21.   在调整元素大小结束之后是否显示动画  
  22.   初始:$('.selector').resizable({ animate: true });  
  23.   获取:var animate = $('.selector').resizable('option''animate');  
  24.   设置:$('.selector').resizable('option''animate'true);  
  25.   
  26. animateDuration : Integer, String : 'slow'   
  27.   动画效果的持续时间。(单位:毫秒)可选值:'slow''normal''fast'  
  28.   初始:$('.selector').resizable({ animateDuration: 500 });  
  29.   获取:var animateDuration = $('.selector').resizable('option''animateDuration');  
  30.   设置:$('.selector').resizable('option''animateDuration', 500);  
  31.   
  32. animateEasing : String : 'swing'  
  33.   选择何种动画效果。  
  34.   初始:$('.selector').resizable({ animateEasing: 'swing' });  
  35.   获取:var animateEasing = $('.selector').resizable('option''animateEasing');  
  36.   设置:$('.selector').resizable('option''animateEasing''swing');  
  37.   
  38. aspectRatio : Boolean, Float : false  
  39.   如果设置为true,则元素的可调整尺寸受原来大小的限制。例如:9 / 16, or 0.5  
  40.   初始:$('.selector').resizable({ aspectRatio: .75 });  
  41.   获取:var aspectRatio = $('.selector').resizable('option''aspectRatio');  
  42.   设置:$('.selector').resizable('option''aspectRatio', .75);  
  43.   
  44. autoHide : Boolean : false  
  45.   如果设置为true,则默认隐藏掉可调整大小的手柄,除非鼠标移至元素上。  
  46.   初始:$('.selector').resizable({ autoHide: true });  
  47.   获取:var autoHide = $('.selector').resizable('option''autoHide');  
  48.   设置:$('.selector').resizable('option''autoHide'true);  
  49.   
  50. cancel : Selector : ':input,option'  
  51.   阻止resizable插件加载在与你匹配的元素上。  
  52.   初始:$('.selector').resizable({ cancel: ':input,option' });  
  53.   获取:var cancel = $('.selector').resizable('option''cancel');  
  54.   设置:$('.selector').resizable('option''cancel'':input,option');  
  55.   
  56. containment : String, Element, Selector : false  
  57.   控制元素只能在某一个元素的大小之内改变。允许值:'parent''document', DOM元素, 或一个选择器.  
  58.   初始:$('.selector').resizable({ containment: 'parent' });  
  59.   获取:var containment = $('.selector').resizable('option''containment');  
  60.   设置:$('.selector').resizable('option''containment''parent');  
  61.   
  62. delay : Integer : 0  
  63.   以毫秒为单位,当发生鼠标点击手柄改变大小,延迟多少毫秒后才激活事件。  
  64.   初始:$('.selector').resizable({ delay: 20 });  
  65.   获取:var delay = $('.selector').resizable('option''delay');  
  66.   设置:$('.selector').resizable('option''delay', 20);  
  67.   
  68. distance : Integer : 1  
  69.   以像素为单位,当发生鼠标点击手柄改变大小,延迟多少像素后才激活事件。  
  70.   初始:$('.selector').resizable({ distance: 20 });  
  71.   获取:var distance = $('.selector').resizable('option''distance');  
  72.   设置:$('.selector').resizable('option''distance', 20);  
  73.   
  74. ghost : Boolean : false  
  75.   如果设置为true,则在调整元素大小时,有一个半透明的辅助对象显示。  
  76.   初始:$('.selector').resizable({ ghost: true });  
  77.   获取:var grid = $('.selector').resizable('option''ghost');  
  78.   设置:$('.selector').resizable('option''ghost'true);  
  79.   
  80. grid : Array : false  
  81.   设置元素调整的大小随网格变化,允许的数据为:{x,y}  
  82.   初始:$('.selector').resizable({ grid: [50, 50] });  
  83.   获取:var grid = $('.selector').resizable('option''grid');  
  84.   设置:$('.selector').resizable('option''grid', [50, 50]);  
  85.   
  86. handles : String, Object : 'e, s, se'  
  87.   设置resizable插件允许生成在元素的哪个边上,可选值:n, e, s, w, ne, se, sw, nw, all  
  88.   初始:$('.selector').resizable({ handles: 'n, e, s, w' });  
  89.   获取:var handles = $('.selector').resizable('option''handles');  
  90.   设置:$('.selector').resizable('option''handles''n, e, s, w');  
  91.   
  92. helper : String : false  
  93.   一个CSS类,当调整元素大小时,将被添加到辅助元素中,一但调整结束则恢复正常。  
  94.   初始:$('.selector').resizable({ helper: 'ui-state-highlight' });  
  95.   获取:var helper = $('.selector').resizable('option''helper');  
  96.   设置:$('.selector').resizable('option''helper''ui-state-highlight');  
  97.   
  98. maxHeight : Integer : null  
  99.   设置允许元素调整的最大高度。  
  100.   初始:$('.selector').resizable({ maxHeight: 300 });  
  101.   获取:var maxHeight = $('.selector').resizable('option''maxHeight');  
  102.   设置:$('.selector').resizable('option''maxHeight', 300);  
  103.   
  104. maxWidth : Integer : null  
  105.   设置允许元素调整的最大宽度。  
  106.   初始:$('.selector').resizable({ maxWidth: 250 });  
  107.   获取:var maxWidth = $('.selector').resizable('option''maxWidth');  
  108.   设置:$('.selector').resizable('option''maxWidth', 250);  
  109.   
  110. minHeight : Integer : 10  
  111.   设置允许元素调整的最小高度。  
  112.   初始:$('.selector').resizable({ minHeight: 150 });  
  113.   获取:var minHeight = $('.selector').resizable('option''minHeight');  
  114.   设置:$('.selector').resizable('option''minHeight', 150);  
  115.   
  116. minWidth : Integer : 10  
  117.   设置允许元素调整的最小宽度。  
  118.   初始:$('.selector').resizable({ minWidth: 75 });  
  119.   获取:var minWidth = $('.selector').resizable('option''minWidth');  
  120.   设置:$('.selector').resizable('option''minWidth', 75);  
  121.   
  122.   
  123. ·事件  
  124. start  
  125.   当元素调整动作开始时触发。  
  126.   初始:$('.selector').resizable({ start: function(event, ui) { ... } });  
  127.   绑定:$('.selector').bind('resizestart'function(event, ui) { ... });  
  128.   
  129. resize  
  130.   当元素调整动作过程中触发。  
  131.   初始:$('.selector').resizable({ resize: function(event, ui) { ... } });  
  132.   绑定:$('.selector').bind('resize'function(event, ui) { ... });  
  133.   
  134. stop  
  135.   当元素调整动作结束时触发。  
  136.   初始:$('.selector').resizable({ stop: function(event, ui) { ... } });  
  137.   绑定:$('.selector').bind('resizestop'function(event, ui) { ... });  
  138.   
  139.   
  140. ·方法  
  141. destory  
  142.   从元素中移除拖拽功能。  
  143.   用法:.droppable( 'destroy' )  
  144.   
  145. disable  
  146.   禁用元素的拖拽功能。  
  147.   用法:.droppable( 'disable' )  
  148.   
  149. enable  
  150.   启用元素的拖拽功能。  
  151.   用法:.droppable( 'enable' )  
  152.   
  153. option  
  154.   获取或设置元素的参数。  
  155.   用法:.droppable( 'option' , optionName , [value] )  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果您想使用jQuery Resizable或React-Resizable库来实现调整列宽的功能,可以按照以下步骤进行设置。 使用jQuery Resizable: 1. 引入jQuery库和jQuery Resizable插件的相关文件。 2. 在表格的表头单元格中添加一个可调整列宽的元素,例如一个`<div>`。 3. 使用jQuery Resizable插件对该元素进行初始化,并设置适当的选项,如`handles`、`minWidth`、`maxWidth`等。 4. 在调整列宽时,更新相应列的宽度。 示例代码: ```html <!DOCTYPE html> <html> <head> <title>调整列宽</title> <link rel="stylesheet" href="jquery-ui.css"> <script src="jquery.js"></script> <script src="jquery-ui.js"></script> <style> table { width: 100%; table-layout: fixed; } th, td { padding: 5px; } .resize-handle { width: 5px; background-color: #ccc; cursor: col-resize; } </style> <script> $(function() { $('.resize-handle').resizable({ handles: 'e', // 只允许水平调整 minWidth: 50, maxWidth: 200 }).on('resize', function() { var columnWidth = $(this).width(); var columnIndex = $(this).parent().index(); $('table tr').each(function() { $(this).find('th, td').eq(columnIndex).width(columnWidth); }); }); }); </script> </head> <body> <table> <thead> <tr> <th><div class="resize-handle"></div>列1</th> <th><div class="resize-handle"></div>列2</th> <th><div class="resize-handle"></div>列3</th> </tr> </thead> <tbody> <tr> <td>内容1</td> <td>内容2</td> <td>内容3</td> </tr> </tbody> </table> </body> </html> ``` 使用React-Resizable: 1. 安装React-Resizable库并导入所需的组件。 2. 在表格的表头单元格中包裹一个可调整列宽的组件,例如`<Resizable>`。 3. 设置`<Resizable>`组件的属性,如`axis`、`minWidth`、`maxWidth`等。 4. 在调整列宽时,更新相应列的宽度。 示例代码: ```jsx import React from 'react'; import { Resizable } from 'react-resizable'; const Table = () => { const handleResize = (index, width) => { // 更新相应列的宽度 // ... }; return ( <table> <thead> <tr> <th> <Resizable axis="x" width={100} height={0} minConstraints={[50, 0]} maxConstraints={[200, 0]} onResize={(e, { size }) => handleResize(0, size.width)} > 列1 </Resizable> </th> <th> <Resizable axis="x" width={100} height={0} minConstraints={[50, 0]} maxConstraints={[200, 0]} onResize={(e, { size }) => handleResize(1, size.width)} > 列2 </Resizable> </th> <th> <Resizable axis="x" width={100} height={0} minConstraints={[50, 0]} maxConstraints={[200, 0]} onResize={(e, { size }) => handleResize(2, size.width)} > 列3 </Resizable> </th> </tr> </thead> <tbody> <tr> <td>内容1</td> <td>内容2</td> <td>内容3</td> </tr> </tbody> </table> ); }; export default Table; ``` 这是一个基本的示例,您可以根据具体需求进行进一步自定义和调整。请确保已正确引入相关的库文件,并按照库的文档说明进行设置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值