问题描述
|
使用jQuery UI Resizable重新调整div / element的大小后,是否有任何方法来获取它的大小?
解决方法
$( \".selector\" ).resizable({
stop: function(event,ui) {
var width = ui.size.width;
var height = ui.size.height;
}
});
,$( \"#resizable\" ).resizable({
stop: function( event,ui ) {
height = $(\"#resizable\").height();
width = $(\"#resizable\").width();
}
});
,您可以始终在jQuery元素上使用height()和width()
,在可调整大小的初始化对象中,为the2 define事件定义一个处理程序,然后在其中检查大小。
$( \".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
});
,为\'stop \'事件添加一个处理程序。
$(\"#element\").resizable({
stop: function(event,ui) {
var x = $(event.target).width();
...
}
});
您还可以绑定到resizestop。
http://jqueryui.com/demos/resizable/#event-stop