【问题标题】:Resize Svg Image Using Jquery on Button click在按钮单击时使用 Jquery 调整 Svg 图像的大小
【发布时间】:2017-05-04 12:40:57
【问题描述】:

嗨,我看到了使用 jquery 调整 svg 图像大小的代码。请看这个

$('.resize').resizable({
    ghost: true,
    resize: function( event, ui ) {
    	var width = ui.size.width;
      var height = ui.size.height;
      $('image').attr('width',width);
      $('image').attr('height',height);
    }
            });
            
var position = $('svg').position();
$('.resize').css('top',position.top);
$('.resize').css('left',position.left);
.resize{
  height: 120px;
  width: 120px;
  position:absolute;
  z-index:0;
}
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<div class="resize">
resize helper
</div>
  <div class='resize-plus'></div>
<div class='resize-minus'></div>

<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" width="800" height="420" id="svg">
    <image height="120" width="120" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://designpieces.com/wp-content/uploads/2013/04/chrome.png" ></image>
</svg>

现在我有了带有 resize-plus ,resize-minus 类的 div .如果我们点击resize-plus我需要增加svg的大小,如果resize-minus我需要减少svg的大小。也就是说resize功能需要在这两个div中修改。 那么该怎么做呢?以及如何设置条件,例如图像大小是否大于和小于 resize 。 谢谢你 。

【问题讨论】:

  • 给你的 SVG 一个 viewBox,减小 viewBox 的大小来放大,增加它来缩小。

标签: javascript jquery jquery-ui svg jquery-plugins


【解决方案1】:

我已经为+- div 添加了函数。

看看下面的小提琴:

DEMO

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-20
    • 1970-01-01
    • 2015-02-11
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    相关资源
    最近更新 更多