html表内画斜线,使用HTML的canvas,给表格画斜线-Go语言中文社区

使用HTML的canvas,给表格中画斜线

给表格加斜线

table,td{

border:2px solid black;

border-collapse:collapse;

}

#header{

width:80px;

height:40px;

}

function line(header,line_width,line_color,line_number){

var table = document.getElementById(header);

var xpos = table.clientWidth;

var ypos = table.clientHeight;

var canvas = document.getElementById('line');

if(canvas.getContext){

var ctx = canvas.getContext('2d');

ctx.clearRect(0,0,xpos,ypos); //清空画布,多个表格时使用

ctx.fill();

ctx.lineWidth = line_width;

ctx.strokeStyle = line_color;

ctx.beginPath();

switch(line_number){

case 1:

ctx.moveTo(0,0);

ctx.lineTo(xpos,ypos);

break;

case 2:

ctx.moveTo(0,0);

ctx.lineTo(xpos/2,ypos);

ctx.moveTo(0,0);

ctx.lineTo(xpos,ypos/2);

break;

case 3:

ctx.moveTo(0,0);

ctx.lineTo(xpos,ypos);

ctx.moveTo(0,0);

ctx.lineTo(xpos/2,ypos);

ctx.moveTo(0,0);

ctx.lineTo(xpos,ypos/2);

break;

default:

return 0;

}

ctx.stroke();

ctx.closePath();

document.getElementById(header).style.backgroundImage = 'url("' + ctx.canvas.toDataURL() + '")';

document.getElementById(header).style.background-attachment= 'fixed';

}

}

window.onload = function (){

line('header',2,'black',3);

//目标单元格,线的宽度,线的颜色,线的条数,1~3,

//line('two',2,'black',2);

}

window.onresize = function(){//当窗口改变时,也随之改变

//可以加上检测 宽度高度是否变化在执行函数

line('header',2,'black',3);

}

asdasdasdasd
asdasdasdasd
表头asdasdasdasdasd

window.onload = line();这样不能传递参数

window.onload = function (){

line('header',2,'black',1);

//其它函数

}

效果图

一条斜线

e839275aeb0cc61c51394c82c3c84208.png

两条斜线

fb407b23cbb642f303988a258f1811a1.png

三条斜线

63dd1b75528ec31564cd6a3c69143262.png

加背景颜色

105eb1e1731081889618392b4c4e7f23.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值