语法 getscaledheight()
example 1 的中文翻译为:示例1 使用getscaledheight方法
让我们看一个代码示例,以查看在使用getscaledheight方法时记录的输出。在这种情况下,将返回对象的高度。
<!doctype html> <html> <head> <!-- adding the fabric js library--> <script src=https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js></script> </head> <body> <h2>using the getscaledheight method</h2> <p>you can open console from dev tools and see that the height value is being displayed in the console</p> <canvas id=canvas></canvas> <script> // initiate a canvas instance var canvas = new fabric.canvas(canvas); canvas.setwidth(document.body.scrollwidth); canvas.setheight(250); // initiate a text object var text = new fabric.text(add sampletext here, { width: 300, fill: green, fontweight: bold, }); // add it to the canvas canvas.add(text); // using getscaledheight method console.log(the scaled height is, text.getscaledheight()); </script> </body> </html>
example 2的翻译为:示例2 使用getscaledheight方法并传递scaley属性
let’s see a code example to see the logged output when the getscaledheight method is used in conjunction with the scaley property. in this case, final scaled height will be displayed in the console.
<!doctype html> <html> <head> <!-- adding the fabric js library--> <script src=https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js></script> </head> <body> <h2>using the getscaledheight method and passing the scaley property</h2> <p>you can open console from dev tools and see that the height value is being displayed in the console has increased </p> <canvas id=canvas></canvas> <script> // initiate a canvas instance var canvas = new fabric.canvas(canvas); canvas.setwidth(document.body.scrollwidth); canvas.setheight(250); // initiate a text object var text = new fabric.text(add sampletext here, { width: 300, fill: green, fontweight: bold, scaley: 2, }); // add it to the canvas canvas.add(text); // using getscaledheight method console.log(the scaled height is, text.getscaledheight()); </script> </body> </html>
以上就是如何使用fabricjs获取文本的缩放高度?的详细内容。
