当前位置: 代码迷 >> 综合 >> 10. js-canvas
  详细解决方案

10. js-canvas

热度:81   发布时间:2023-09-19 16:26:09.0

onmousedown 鼠标按键 (event)

onmousemove 鼠标移动 (event)

onmouseup      鼠标松开 (event)

<canvas id="tutorial" width="150" height="150"></canvas>
初始 300*150

 只有两个属性:width  height  可以使用DOM的properties来设置。

 getContext()获得渲染上下文和它的绘画功能

//固定格式
var canvas = document.getElementById('tutorial');
if (canvas.getContext) {var ctx = canvas.getContext('2d');
}
fillStyle //设置样式
fillRect(X,Y,长,宽) //填充矩形
strokeRect //描边(边框)
clearRect  //清除  橡皮擦

in操作符的使用

//数组
var arr = [1,2,3,4]; 
console.log(1 in arr); //数组根据下标查找 下标是1,存在
console.log(4 in arr); //数组根据下标查找 下标是4,不存在//字符串
//var str = 'ffdfsdfsdadw142543拆分';
//console.log('ff' in str); //报错,不支持字符串查找//对象
var obj = {a:1,b:2,c:3};
console.log('a' in obj);
console.log('c' in obj);
console.log('0' in obj);

 判断ontouchstart是否在手机上操作  特性检测

document.body.ontouchstart === undefined  如果等于,不是在手机上触发