您现在的位置是:网站首页> 编程资料编程资料
html5 canvas实现跟随鼠标旋转的箭头_html5_网页制作_
2023-11-11
327人已围观
简介 这篇文章主要为大家详细介绍了html5 canvas实现跟随鼠标旋转的箭头,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了
XML/HTML Code复制内容到剪贴板
- >
- <html>
- <head>
- <meta charset="utf-8" />
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
- <title>canvas实现跟随鼠标旋转的箭头title>
- <style>
- *{padding: 0;margin: 0}
- style>
- head>
- <body>
- <canvas width="500" height="500" style="border: 1px solid #555; display: block;margin: 0 auto;">canvas>
- <script>
- var arrow=function () {
- this.x=0;
- this.y=0;
- this.color="#f90"
- this.rolation=0;
- }
- var canvas=document.querySelector('canvas')
- var ctx=canvas.getContext('2d');
- arrow.prototype.draw=function (ctx) {
- ctx.save();
- ctx.translate(this.x,this.y);
- ctx.rotate(this.rolation)
- ctx.fillStyle=this.color;
- ctx.beginPath();
- ctx.moveTo(0, 15);
- ctx.lineTo(-50, 15);
- ctx.lineTo(-50, -15);
- ctx.lineTo(0,-15);
- ctx.lineTo(0,-35);
- ctx.lineTo(50,0);
- ctx.lineTo(0,35);
- ctx.closePath()
- ctx.fill();
- ctx.restore();
- }
- var Arrow=new arrow();
- Arrow.x=canvas.width/2;
- Arrow.y=canvas.height/2;
- var c_x,c_y; //相对于canvas坐标的位置;
- var isMouseDown=false;
- Arrow.draw(ctx)
- canvas.addEventListener('mousedown',function(e) {
- isMouseDown=true;
- },false)
- canvas.addEventListener('mousemove',function(e) {
- if(isMouseDown==true){
- c_x=getPos(e).x-canvas.offsetLeft;
- c_y=getPos(e).y-canvas.offsetTop;
- //setInterval(drawFram,1000/60)
- req
相关内容
- Html5 postMessage实现跨域消息传递_html5_网页制作_
- html5 touch事件实现页面上下滑动效果【附代码】_html5_网页制作_
- html5 touch事件实现触屏页面上下滑动(二)_html5_网页制作_
- html5 touch事件实现触屏页面上下滑动(一)_html5_网页制作_
- HTML5离线缓存Manifest是什么_html5_网页制作_
- HTML5 用动画的表现形式装载图像 _html5_网页制作_
- HTML5 canvas实现雪花飘落特效_html5_网页制作_
- HTML5实现Notification API桌面通知功能 _html5_网页制作_
- 全民水浒 杨志杨雄董平武将详细介绍_手机游戏_游戏攻略_
- 天天爱萌仙 礼包活动详情介绍 充值送豪礼_手机游戏_游戏攻略_
点击排行
本栏推荐
