javascript - SVG 垂直展开线

标签 javascript jquery css d3.js svg

问题是如何在没有 stroke-dasharray 的情况下垂直扩展线。不知道如何做对。这是我的例子:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_3" x="0px" y="0px" width="286px" height="286px" viewBox="0 0 286 286" enable-background="new 0 0 286 286" xml:space="preserve">
        <line fill="none" stroke="#3AB0F3" id="stroke-dasharray" stroke-width="244" stroke-miterlimit="10" x1="143" y1="0" x2="143" y2="286"/><animate
                attributeName="stroke-dasharray"
                from="0, 0" to="143, 143"
                dur="3s"
                repeatCount="1"/></line>
    </svg>

这里的主要问题是如何在 SVG 上设置属性以在没有 stroke-dasharray 的情况下垂直扩展它。

还有一些来自 d3 图表的 jQuery 代码。

var mySVG1 = $('#Layer_3').drawsvg({
                duration: 3000
            });

mySVG1.drawsvg('animate');

最佳答案

这是我在 d3 中的做法:

d3.select('#lineSelect').transition().duration(1000).attr('y2',700)

这会将您的高度从 286 更改为 700。但为了在此处看到这一点,我已将原始高度更改为 2,因为输出窗口很小。

但要真正看到它,您需要它的容器,即调整高度的 svg。暂时我只改成了window.innerHeight,但是可以跟line一样更新。

var height = window.innerHeight;

d3.select('svg').attr('height', height)

d3.select('#lineSelect').transition().delay(500).duration(1000).attr('y2',700) //transition height after half a second
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" width="286px" height="286px" viewBox="0 0 286 286" enable-background="new 0 0 286 286" xml:space="preserve">
  <line id='lineSelect' fill="none" stroke="#3AB0F3" stroke-width="244" stroke-miterlimit="10" x1="143" y1="0" x2="143" y2="2" />
</svg>

fiddle :https://jsfiddle.net/thatOneGuy/27u7g3dt/2/

关于javascript - SVG 垂直展开线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37182296/

相关文章:

javascript - 如何在文件 : protocol 处使用 webkitRequestFileSystem

javascript - Angular 4 - 从服务到组件捕获错误对象

jQuery 意外的可排序行为

HTML <br/> 标签打破 <code> 段?

javascript - 有没有办法使用 javascript 或 Jquery 找出某人计算机上屏幕的宽度?

css - 类扩展 CSS

javascript - 加载图像后重定向

jquery - 模态窗口中的 YouTube 播放器

javascript - CSS - 使可拖动的自定义列表项响应

javascript - 如何让 jQuery 或 Javascript 根据当前 url 更改 css?