jQuery - 检测文本区域大小何时调整

标签 jquery resize textarea bind

我试图检测用户何时调整可调整大小的文本区域的大小..

我试图用这段代码来做到这一点,但它不起作用:

$('textarea.note').bind("resize", function(){

  alert("resize!!!!!");


})

我真的不想使用任何类型的计时器和循环..帮助!?

最佳答案

DEMO

$(document).ready(function () {
    var $textareas = jQuery('textarea');

    // set init (default) state   
    $textareas.data('x', $textareas.outerWidth());
    $textareas.data('y', $textareas.outerHeight());

    $textareas.mouseup(function () {

        var $this = $(this);

        if ($this.outerWidth() != $this.data('x') || $this.outerHeight() != $this.data('y')) {
            alert($this.outerWidth() + ' - ' + $this.data('x') + '\n' + $this.outerHeight() + ' - ' + $this.data('y'));
        }

        // set new height/width
        $this.data('x', $this.outerWidth());
        $this.data('y', $this.outerHeight());
    });
});

关于jQuery - 检测文本区域大小何时调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18393172/

相关文章:

javascript - 溢出 :hidden and :after pseudo-selector

javascript - 在调整窗口大小时更新 Angular 服务变量

jQuery this() 用于文本区域?

php - 文本区域不能有默认值

javascript - 当我单击 html "<a>Download</a>"中的 anchor 时,我正在尝试下载 excel 文件

jquery - 在 jQuery ajax 回调函数中访问数组值

javascript - Jquery 复选框选择迭代

javascript - 我想知道 js fiddle 如何处理有关调整大小和布局的文本区域

JavaFX 缩小 ImageView 尺寸

html - html5 拼写检查属性如何工作?