显示鼠标滑动轨迹
程序员文章站
2022-06-27 22:22:46
``` Tracks 在第一排的方块中滑动鼠标 重置 ``` ......
<!doctype html> <html lang="zh"> <head> <meta charset="utf-8"> <title>tracks</title> <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script> <style> * { margin: 0; padding: 0; border: 0; } .track-monitor { background-color: chocolate; } .track-pad { height: 200px; background-color: dimgray; } .track-coordinate { background-color: purple; color: white; height: 25px; line-height: 25px; font-size: 12px; } .track-coordinate-list { font-size: 12px; width: 100%; word-break: break-word; } </style> <script> window.addeventlistener('load', function () { var pad = document.getelementsbyclassname('track-pad')[0]; var monitor = document.getelementsbyclassname('track-monitor')[0]; var coordinate = document.getelementsbyclassname('track-coordinate')[0]; var clist = document.getelementsbyclassname('track-coordinate-list')[0]; var reset = document.getelementsbytagname('button')[0]; var context = monitor.getcontext('2d'); var cset = []; var startx = 0, starty = 0; $('div').mousedown(mousestate).mouseup(mousestate); function fixsize() { monitor.width = window.innerwidth; }; function log(e) { if (cset.length == 0) { context.moveto(e.x, e.y); } else { context.strokestyle = 'white'; context.lineto(e.x, e.y); context.stroke(); } if (e.x - startx == e.x && e.y - starty == e.y) { startx = e.x; starty = e.y; } coordinate.innerhtml = '(' + (e.x - startx) + ', ' + (e.y - starty) + ')'; cset.push(coordinate.innerhtml); clist.innerhtml = cset.join(', '); } function mousestate(e) { if (e.type == "mouseup") { $('#logs').append('<br/>' + cset.join(', ')); clist.innerhtml = cset.join(''); cset = []; pad.removeeventlistener("mousemove", log); } if (e.type == "mousedown") { startx = 0; starty = 0; pad.addeventlistener('mousemove', log); } } reset.addeventlistener('click', function () { fixsize(); cset = []; clist.innerhtml = ''; coordinate.innerhtml = '在第一排的方块中滑动鼠标'; }); fixsize(); }); </script> </head> <body> <div class="stage"> <div class="track-pad"></div> <canvas width="100" height="200" class="track-monitor"></canvas> <div class="track-coordinate">在第一排的方块中滑动鼠标</div> <button>重置</button> <div> <div id="logs"></div> <div class="track-coordinate-list"></div> </div> </div> </body> </html>
上一篇: OpenCV:图像的裁剪
下一篇: Python进阶:metaclass谈
推荐阅读
-
ZedGraph的曲线的LineItem对象的Tag属性存储信息进而在鼠标悬浮时进行显示
-
Android Studio移动鼠标显示悬浮提示的设置方法
-
jQuery响应鼠标事件并隐藏与显示input默认值
-
千影浏览器怎么隐藏鼠标指针的移动轨迹?
-
Axure怎么制作鼠标悬停下拉菜单显示的特效?
-
python+matplotlib实现鼠标移动三角形高亮及索引显示
-
Android中使用ScrollView实现滑动到底部显示加载更多
-
JGUI源码:Accordion鼠标中键滚动和手机端滑动实现
-
echarts鼠标覆盖高亮显示节点及关系名称详解
-
Android搜索结果显示高亮实例(有数据滑动底部自动刷新)