Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
How to set diffedert parameter for resizable elements in jQuery UI

I work with the dragable and resizable elements, and i have 2 types of box on page, small without image, and big with image.

For this 2 element i have resizable text on box, i create func when user start to resize element withd of text are changing, for big box it's working normal, for small no.

I fond the problem here:

 $('.box').resizable({
          minWidth: 50,
          minHeight: 44,
          maxWidth: 205,
          maxHeight: 87,
          resize: function(event, ui) {
            var size = ui.size;
            $(this).children().css('font-size', (size.width * size.height) / 580 + 'px');
            $(this).css('font-size', (size.width * size.height) / 580 + 'px');
          }
        });

For small box i want to set this paramater:

$('.box').resizable({
          minWidth: 20,
          minHeight: 24,
          maxWidth: 100,
          maxHeight: 87,
          resize: function(event, ui) {
            var size = ui.size;
            $(this).children().css('font-size', (size.width * size.height) / 580 + 'px');
            $(this).css('font-size', (size.width * size.height) / 580 + 'px');
          }
        });

If i set different parameter for small element than it's working normal. How i can set different parameter for objects. Plus i have dynamically creation of object in the view.

My code - jsFiddle

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I have worked on your example here: https://jsfiddle.net/Twisty/czhLjtud/12/

JavaScript

$(function() {
  function calcFont(s) {
    var result = Math.round((s.width * s.height) / 580);
    return result + "px";
  }

  $('.lpms3-box').draggable();

  $('.lpms3-box > .box').resizable({
    minWidth: 50,
    minHeight: 44,
    maxWidth: 205,
    maxHeight: 87,
    resize: function(event, ui) {
      var newFont = calcFont(ui.size);
      console.log(ui.size.width, ui.size.height, (ui.size.width * ui.size.height) / 580, "Set new font: " + newFont);
      $(this).css('font-size', newFont);
    }
  });
});

This appears to work for both boxes. It's not clear why it is not working for you.

For math, it is best to wrap all parts in ( and ) before appending any string items. So for example:

(size.width * size.height) / 580 + 'px'

This code is sort of ambiguous, + may be read as the wrong operator. I suggest this:

((size.width * size.height) / 580) + 'px'

This way the code knows the proper operations and will use + as the concat operator and not the addition operator.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda