Skip to content

Commit c7b48e4

Browse files
authored
Merge pull request #15 from ls-v/patch-1
Update fiximgclick.js
2 parents 7caf422 + 24bf5c6 commit c7b48e4

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

_src/plugins/fiximgclick.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,30 @@ UE.plugins["fiximgclick"] = (function () {
143143
},
144144
updateTargetElement: function () {
145145
var me = this;
146+
// 拿到图片的原始大小
147+
var o_width = me.target.naturalWidth;
148+
var o_height = me.target.naturalHeight;
149+
150+
// 计算出原始图片比例
151+
var o_scale = (o_width / o_height).toFixed(4);
152+
153+
// 再拿到图片现在的大小,可能是变形的Ï
154+
var width = parseInt(me.resizer.style.width);
155+
var height = parseInt(me.resizer.style.height);
156+
157+
// 判断改变的是宽度还是高度
158+
if (rect[me.dragId][2] != 0) {
159+
height = width / o_scale;
160+
} else if (rect[me.dragId][3] != 0) {
161+
width = height * o_scale;
162+
}
163+
146164
domUtils.setStyles(me.target, {
147-
width: me.resizer.style.width,
148-
height: me.resizer.style.height
165+
width: width + "px",
166+
height: height + "px",
149167
});
150-
me.target.width = parseInt(me.resizer.style.width);
151-
me.target.height = parseInt(me.resizer.style.height);
168+
me.target.width = width;
169+
me.target.height = height;
152170
me.attachTo(me.target);
153171
},
154172
updateContainerStyle: function (dir, offset) {

0 commit comments

Comments
 (0)