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
How to get width and height after JQuery Resizable stops?
提问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
回答by RwwL
In your init object for the resizables, define a hander for the resizestop
event, 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。