简体   繁体   English

使用javascript进行贝塞尔曲线的长度

[英]Length of Bezier curve with javascript

I draw a text along a path with Keith Wood's jQuery SVG plugin. 我用Keith Wood的jQuery SVG插件沿着路径绘制文本。 How can I get a length of the path with JS? 我怎样才能获得JS的路径长度?

From the SVG specification, use path.getTotalLength() . 从SVG规范中,使用path.getTotalLength()

Here's a minimal example of how to use this with the jquery-svg library: 这是一个如何在jquery-svg库中使用它的最小示例:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>jQuery SVG Basics</title>
<style type="text/css">
@import "jquery.svg.css";

#mydiv { width: 400px; height: 300px; border: 1px solid #484; }
</style>
<script type="text/javascript" src="jquery-1.6.2.js"></script>
<script type="text/javascript" src="jquery.svg.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $("#mydiv").svg({
        onLoad : function(svg){
            var path = svg.createPath(); 
            var pathNode = svg.path(path.move(100, 200).curveC([[200, 
                100, 300, 0, 400, 100], [500, 200, 600, 300, 700, 
                200], [800, 100, 900, 100, 900, 100]]));

            console.log(pathNode.getTotalLength());

        }
    });
});
</script>
</head>
<body>
<div id="mydiv"></div>
</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM