Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
¿Cómo actualizar una forma fabric.js agregada tan pronto como se cambia de tamaño?

Estoy trabajando en Fabric Grid usando Fabric.js y quiero agregar las dimensiones de la forma que se agrega en el lienzo. El nuevo ancho y alto están definidos, pero necesitaré no solo mostrar las dimensiones en la pantalla, sino también actualizarlo cuando cambie el tamaño de la forma.

A continuación se muestra la función JS, donde se definen newWidth y newHeight :

 function snapToGrid() { let checkBox = document.getElementById("myCheck"); if (checkBox.checked == true) { //snap only to the grid const gridSize = 50; c.on("object:moving", function (options) { options.target.set({ left: Math.round(options.target.left / gridSize) * gridSize, top: Math.round(options.target.top / gridSize) * gridSize, }); }); c.on("object:modified", function (options) { var newWidth = Math.round(options.target.getWidth() / gridSize) * gridSize; var newHeight = Math.round(options.target.getHeight() / gridSize) * gridSize; options.target.set({ width: newWidth, height: newHeight, scaleX: 1, scaleY: 1, }); }); } else { c.off("object:modified"); c.off("object:moving"); } }

Soy nuevo en Fabric.js y agradecería que alguien me ayudara con esto. Avíseme si tengo que compartir más detalles del código.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

De acuerdo, respondí mi propia pregunta, así que si alguien lo necesita, aquí está el código a continuación que ayudaría a mostrar dinámicamente el ancho y la altura de su forma mientras está alterada.

 function onObjectScaled(e){ var scaledObject = e.target; var text = document.getElementById("text"); text.value = 'Width = '+scaledObject.getWidth() + ' Height = '+scaledObject.getHeight(); }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!