Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - Detect when textarea is resized [duplicate]

I am trying to detect whenever the user resizes a resizable textarea..

I am trying to do it with this code but it doesn't work:

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

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


})

I don't want really to use any kind of timer and loops.. Help!?

like image 876
John Black Avatar asked Jan 13 '23 13:01

John Black


1 Answers

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());
    });
});
like image 147
Tushar Gupta - curioustushar Avatar answered Jan 19 '23 01:01

Tushar Gupta - curioustushar