我今天有兩個放大縮小按鈕,想讓user按放大時用js把一個100x72的圖片
以寬為主每次加4px等比放大,反之亦然,但不知道小數位數該如何取才能正確控制高度
等比放大的公式為

I have two button to let user enlarge or reduce a 100px x 72px image
immediately on the page, 4px enlarge or reduce one time by width, but
I don't know how to control the height to make resize proportionally.

resize formula is below:

enlarge
(height/width)*(width+4)

reduce
(height/width)*(width-4)

I try to use xnview software to get the resize information, you can
see, the height will not resize proportionally after few clicks, for
example, if I click reduce 10 times, and click enlarge 10 times, the
image should be origin size 100x72, but it's not, how to do it right?

xnview reduce
100 72
96 69
92 66
88 63
84 60
80 58
76 55

JS reduce
100 72
96 69.12
92 66.125
88 63.130434782608695
84 60.13636363636364
80 57.142857142857146
76 54.15

xnview enlarge
100 72
104 75
108 78
112 81
116 84
120 86
124 89

JS enlarge
100 72
104 74.88
108 77.88461538461539
112 80.88888888888889
116 83.89285714285714
120 86.89655172413794
124 89.89999999999999

Reply via email to