javascript-HTML画布使形状模糊
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript-HTML画布使形状模糊,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1597字,纯文字阅读大概需要3分钟。
内容图文
![javascript-HTML画布使形状模糊](/upload/InfoBanner/zyjiaocheng/690/2f15606c870d4660a05653c97e63de39.jpg)
我想使用HTML制作简单的形状.
但是形状必须很大.
画布全屏显示
例如:http://jsfiddle.net/xLgg43s9/1/embedded/result/
码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
* { margin: 0; padding: 0;}
body, html { height:100%; }
#canvas {
position:absolute;
width:100%;
height:100%;
}
</style>
</head>
<body>
<canvas id="canvas">
</canvas>
<script>
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
ctx.fillStyle = "#000";
var w=canvas.width;
var h=canvas.height;
ctx.fillRect(0,0,w,h);
ctx.fillStyle="#fff";
ctx.beginPath();
var a=w/2;
var b=0;
ctx.arc(a,b,20,0,Math.PI,false);
ctx.closePath();
ctx.fill();
ctx.stroke();
ctx.beginPath();
ctx.fillStyle="red";
ctx.fillRect(0,0,10,100);
ctx.stroke();
ctx.save();
ctx.translate(240, 120);
ctx.rotate(Math.PI / 4); // 45 degrees
ctx.fillStyle = "yellow";
ctx.fillRect(-40, -40, 20, 20);
ctx.restore();
</script>
</body>
</html>
请修复它.
解决方法:
不要通过CSS设置画布的大小,因为CSS会拉伸canvas元素,而不是实际使画布变大.
改用HTML属性:
<canvas id="canvas" width="500" height="500"></canvas>
现在,由于您要将画布设置为100%的宽度/高度,因此这些预设属性不会帮您实现麻烦,因此您将不得不使用一些JS:
var canvas = document.getElementById("canvas");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var ctx=canvas.getContext("2d");
// etc...
如果要在调整窗口大小时调整画布的大小,建议您查看this answer.
内容总结
以上是互联网集市为您收集整理的javascript-HTML画布使形状模糊全部内容,希望文章能够帮你解决javascript-HTML画布使形状模糊所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。