javascript获取曲线路径每个像素的坐标
javascript获取曲线路径每个像素的坐标
先用svg做个 物体验证路径动画 然后实时获取物体坐标存入数组就行了
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>{$title}</title> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=no" /> <meta name="format-detection" content="telephone=no" /> <!-- Link Swiper's CSS --> <include file="commonheader" /> <style type="text/css"> svg { width: 300px; display: block; position: absolute; } .ball { width: 1px; height: 1px; background-color: red; border-radius: 50%; } .fff{ offset-path: path('M10 80 Q 77.5 10, 145 80 T 280 80'); offset-distance: 0%; animation: red-ball 10s linear forwards; } @keyframes red-ball { from { offset-distance: 0%; } to { offset-distance: 100%; } } </style> </head> <body> <svg width="300px" height="175px" version="1.1"> <path fill="transparent" stroke="#888888" stroke-width="1" d="M10 80 Q 77.5 10, 145 80 T 280 80" class="path"></path> </svg> <div class="ball"></div> <script src="{$yumingnew}/js/jquery.min.js"> </script> <script type="text/javascript"> var lujinglist = []; $(function(){ $('.ball').addClass('fff'); setInterval(function(){ lujinglist.push([$('.ball').offset().left,$('.ball').offset().top]); },30) setTimeout(function(){ console.log(JSON.stringify(lujinglist)); },10000) }) </script> </body> </html>
如果遇到什么不懂的地方直接关注公众号留言(本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。)
作者:newmiracle
出处:https://www.cnblogs.com/newmiracle/