怎么用js输出一个菱形
1个回答
展开全部
方法有很多,我用HTML5的canvas写一个,你直接copy然后创建一个HTML文件,用google浏览器或者火狐亦或是高版本的IE打开就可以看到了
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
body{
margin: 0;
padding: 0;
}
#myCanvas{
margin:200px 600px;
border:5px solid #9c9898
}
</style>
<script type="text/javascript">
window.onload = function(){
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
drawLine(context,250,10,490,250,20,"blue","round");
drawLine(context,490,250,250,490,20,"blue","round");
drawLine(context,250,490,10,250,20,"blue","round");
drawLine(context,10,250,250,10,20,"blue","round");
}
function drawLine(context,startX,startY,endX,endY,lineWidth,strokeStyle,lineCap){
context.beginPath();
context.moveTo(startX,startY);
context.lineTo(endX,endY);
context.lineWidth = lineWidth;
context.strokeStyle = strokeStyle;
context.lineCap = lineCap;
context.stroke();
}
</script>
</head>
<body>
<canvas id="myCanvas" width="500" height="500"></canvas>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询