Resize a div to smaller than its declared size?

前端 未结 6 1015
醉话见心
醉话见心 2021-02-07 14:50

Is there a way to resize a div to smaller than the declared height and width?

I\'m making an application where the user can resize a div and save it. However, when I loa

6条回答
  •  面向向阳花
    2021-02-07 15:23

    In javascript usign jquery:

    //get the current heigt and the width of the element
    var h = $('.cls').height();
    var w = $('.cls').width();
    // i don'T know how you provide your nes size, but once you have in i a variable, you can just do
    if(your_h > h) $('.cls').height(your_h);
    if(your_w > w) $('.cls').width(your_w);
    

    assuming you size are in PX.

    Height() and width() will return the size in px if not arguments are specified. They will set the height and width if you provide a value. If you don't explicitly specify a mesurment, px are used by default.

    On the second part, it simply check if the new size (your_x) is biggre than the originla size, if so, it will resize it, if not it will jut ignore.

    AND YES, jquery will overwide your css specification ;) anyone, biger or smaller values

提交回复
热议问题