jQuery Resizable: doubling the resize width

孤者浪人 提交于 2019-12-02 08:04:28

Given a centered DIV, the best I could think of would be to set the width in the callback.

     $('#divID').resizable({
            handles       : 'e,w'
          , resize        : function (event,ui){
                               ui.position.left = ui.originalPosition.left;
                               ui.size.width    = ( ui.size.width
                                                  - ui.originalSize.width )*2
                                                  + ui.originalSize.width;
                            }
     });

The above simply calculates the difference between the final and original width and multiplies that by two, then adds that to the original width.

I'm not sure this is the best way to do this. I, for one, don't like it since the width is being set twice on the object. I think the better way would be to accept some sort of (xRate or X-Step) and (yRate or Y-Step) option and include that in the _mouseDrag: portion of the jQuery function.

To do this w/o editing jQuery, I think I'd have to create a plugin that overwrites the resizable's _mouseDrag function.

I'll accept better answers! :)

I don't know how you center your resizable but this test case works well for me.

At it's heart I do something similar to vol7ron but I use one assignment less and the calculation is better readable :D just joking choose what you like better fits you more

ui.size.width += ui.size.width - ui.originalSize.width;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!