在DIV中调整SVG大小并且不保留宽高比

时间:2015-07-08 13:14:54

标签: html svg resize jquery-ui-resizable

如何通过jQuery UI在DIV中调整SVG图像的大小?我想调整DIV的大小,并且不保留此DIV中SVG图像的宽高比。

jsFiddle example

HTML

   <div style="width: 100px; height:100px; border: 1px solid black;">
      <svg style="width:100%; height:100%; " version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="340.156px" height="340.152px" viewBox="0 0 340.156 340.152" enable-background="new 0 0 340.156 340.152" xml:space="preserve">
          <path fill="#2121ed" fill-opacity="1" stroke="#000000" stroke-width="1" stroke-opacity="0" class="path_vector_1" d="M340.156,170.078c0,93.926-76.146,170.074-170.077,170.074C76.146,340.152,0,264.004,0,170.078
    C0,76.146,76.147,0,170.079,0C264.011,0,340.156,76.146,340.156,170.078z">
          </path>
      </svg>
  </div>

的jQuery

$('div').resizable();

1 个答案:

答案 0 :(得分:5)

添加preserveAspectRatio =&#34;无&#34;到<svg>元素例如

<svg style="width:100%; height:100%; " version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="340.156px" height="340.152px" viewBox="0 0 340.156 340.152" preserveAspectRatio="none" enable-background="new 0 0 340.156 340.152" xml:space="preserve">