nick lang
nick lang

Reputation: 65

Second call to scale() doesn't scale

In the example in the jsbin, if you click the button once, the rect gets scaled, but the 2nd time, it doesn't scale.

I thought, if you keep calling scale(0.75) then it would scale the rect 75% of its current size, so it would basically keep getting smaller and smaller.

I'm sure I'm missing something very basic since my example is very simple, but I've read so much documentation, and I still can't figure it out. Any ideas?

http://jsbin.com/zajehudurido

Upvotes: 0

Views: 55

Answers (1)

dds
dds

Reputation: 2415

It's because the rect is scaled from original size, you set once you created it (350x350). If you want to scale it from actual size every time, you need to recalculate the argument to the rect.scale method. E.g. save the previous value and multiply it on 0.75 every time:

var ratio = 1;
function resize() {
    ratio =  ratio * 0.75;
    rect.scale(ratio);
    canvas.renderAll();
}

Upvotes: 1

Related Questions