【问题标题】:jQuery UI: Resizable: catch the resize eventjQuery UI:可调整大小:捕获调整大小事件
【发布时间】:2015-10-04 13:39:10
【问题描述】:

我有一个可调整大小的 div,现在我想在调整此框的大小/用户完成调整大小时编辑一个 cookie。 (我有cookie插件)

我该怎么做?

PS:我有多个 .div 的 ID 不同。

<div class="div" id="div1"></div>
<div class="div" id="div2"></div>

我的代码不起作用(它不保存 cookie)

$( ".div" ).resizable({
    handles: \'s\',
    onResize: function(size) {
        $.cookie("div_height", this.height);
    }
});

【问题讨论】:

  • 请解释一下不起作用。它不调整大小还是不保存cookie?请更具体
  • Read the documentation。要使用的事件是stop 而不是onResize

标签: javascript jquery jquery-ui cookies


【解决方案1】:

使用此代码

$( ".div" ).resizable({
   handles: \'s\',
   stop: function(e,ui) {
      $.cookie("div_height", ui.size.height);
   }
});

【讨论】:

  • 这工作到目前为止,但 cookie 值是“未定义”。 this.height 参数不正确,不是吗?
【解决方案2】:

这是一个用于捕获调整大小事件的有效 js fiddle,还有另一个示例,但它非常适合您:http://jsfiddle.net/byrgv6j4/1/

$('.resizable').resizable({
    aspectRatio: true,
    handles: 'ne, se, sw, nw',
    resize: function(e, ui) {
      //console.log(e);  
      //console.log(ui);
      console.log(ui.size.height);
    }
});

如果要获取元素当前状态的高度,则必须获取ui.size.height。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-15
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    相关资源
    最近更新 更多