javascript JQuery Resizable 停止后如何获取宽度和高度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6131642/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 19:36:42  来源:igfitidea点击:

How to get width and height after JQuery Resizable stops?

javascriptjqueryhtmlresize

提问by Dexty

Is there any way of getting the size of a div/element after it has been resized with JQuery UI Resizable?

在使用JQuery UI Resizable调整大小后,有没有办法获取 div/元素的大小?

回答by Iurii Drozdov

$( ".selector" ).resizable({
    stop: function(event, ui) {
        var width = ui.size.width;
        var height = ui.size.height;
    }
});

回答by Dhana

$( "#resizable" ).resizable({

    stop: function( event, ui ) {

        height = $("#resizable").height(); 

        width = $("#resizable").width(); 

    } 
});

回答by pthurlow

you can always use height()and width()on a jQuery element

你总是可以在 jQuery 元素上使用height()width()

回答by RwwL

In your init object for the resizables, define a hander for the resizestopevent, where you can then check the size.

在可调整大小的 init 对象中,为resizestop事件定义一个处理程序,然后您可以在其中检查大小。

$( ".selector" ).resizable({
   stop: function(event, ui) { ... }
     // not 100% sure it'll be event.target that you want,
     // inspect in console to double-check
     var width = $(event.target).width();
     var height = $(event.target).height();
     // do stuff with width & height
});

回答by bgun

Add a handler for the 'stop' event.

为“停止”事件添加处理程序。

$("#element").resizable({
   stop: function(event, ui) {
      var x = $(event.target).width();
      ...
   }
});

You can also bind to resizestop.

您还可以绑定到resizestop

http://jqueryui.com/demos/resizable/#event-stop

http://jqueryui.com/demos/resizable/#event-stop