簡體   English   中英

使用javascript進行貝塞爾曲線的長度

[英]Length of Bezier curve with javascript

我用Keith Wood的jQuery SVG插件沿着路徑繪制文本。 我怎樣才能獲得JS的路徑長度?

從SVG規范中,使用path.getTotalLength()

這是一個如何在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