OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Why are viewportTransform[4] and viewportTransform[5] always negative when using zoomToPoint for zooming in Fabric.js?

  • Thread starter Thread starter olivia
  • Start date Start date
O

olivia

Guest
Code:
<script src="https://unpkg.com/[email protected]/dist/fabric.min.js"></script>
<style>
    canvas {
        border: 1px rgb(0, 0, 0) ;
    }
</style>
</head>
<body>
<canvas id="c"></canvas>
<script>
    var canvas = new fabric.Canvas('c',{width:200, height:200});
    var rect = new fabric.Rect({
        left: 100,
        top: 100,
        stroke: "red",
        strokeWidth: 2, 
        fill:"transparent",
        width: 20,
        height: 20,
        originX:"center", 
        originY:"center"
    });
    canvas.add(rect);

canvas.on('mouse:wheel', function(opt) {
  var delta = opt.e.deltaY;
  var zoom = canvas.getZoom();
  if (delta < 0) {
    zoom += 0.1;
    canvas.zoomToPoint({x:opt.e.offsetX, y:opt.e.offsetY}, zoom);
    console.log("viewportTransform",canvas.viewportTransform);
  } 
  canvas.requestRenderAll();

Why does using the zoomToPoint method for zooming in always result in negative values for viewportTransform[4] and viewportTransform[5], regardless of the point used as the center for zooming?

<pre><code><script src="https://unpkg.com/[email protected]/dist/fabric.min.js"></script>
<style>
canvas {
border: 1px rgb(0, 0, 0) ;
}
</style>
</head>
<body>
<canvas id="c"></canvas>
<script>
var canvas = new fabric.Canvas('c',{width:200, height:200});
var rect = new fabric.Rect({
left: 100,
top: 100,
stroke: "red",
strokeWidth: 2,
fill:"transparent",
width: 20,
height: 20,
originX:"center",
originY:"center"
});
canvas.add(rect);

canvas.on('mouse:wheel', function(opt) {
var delta = opt.e.deltaY;
var zoom = canvas.getZoom();
if (delta < 0) {
zoom += 0.1;
canvas.zoomToPoint({x:opt.e.offsetX, y:opt.e.offsetY}, zoom);
console.log("viewportTransform",canvas.viewportTransform);
}
canvas.requestRenderAll();
</code></pre>
<p>Why does using the zoomToPoint method for zooming in always result in negative values for viewportTransform[4] and viewportTransform[5], regardless of the point used as the center for zooming?</p>
 

Latest posts

S
Replies
0
Views
1
Safwan Aipuram
S
Top