开发者

Reverse jquery resize shift functionality

开发者 https://www.devze.com 2023-02-06 13:02 出处:网络
When you resize a div using jquery resize plugin, ifyou hold the shift key the aspect ratio is kept. Well it is possible to {aspectRatio: true} to option list and if i hold开发者_运维知识库 the shift

When you resize a div using jquery resize plugin, if you hold the shift key the aspect ratio is kept.

Well it is possible to {aspectRatio: true} to option list and if i hold开发者_运维知识库 the shift key to disable the aspect ratio ?

Thanks.


Well i managed by modifying the widget:

replaced

if (this._aspectRatio || b.shiftKey)

with

if (this._aspectRatio && !b.shiftKey)


You can monkey-patch the jquery resizable code for that without touching the source file, so you could still use its CDN.

var mouseDrag = $.ui.resizable.prototype._mouseDrag;
$.ui.resizable.prototype._mouseDrag = function (event) {
    event.shiftKey = !event.shiftKey;
    var aspectRatio = this._aspectRatio;
    this._aspectRatio = aspectRatio && event.shiftKey;
    mouseDrag.apply(this, arguments);
    this._aspectRatio = aspectRatio;
};
0

精彩评论

暂无评论...
验证码 换一张
取 消