单元格中添加自适应斜线

1.页面效果
在这里插入图片描述

2.jsp代码

<canvas id="line" style="display: none;"></canvas>

。。。。。。。。。。省略其他代码

<td  id='classify'>
	<div class='date'>日期</div>
	<div class='time'>时间</div>
</td>

3.css代码

.date {
	float: right;
}

.time {
	float: left;
}

4.js代码

function line() {
	var canvas = document.getElementById("line");
	var width = $("#classify").width(); //获取单元格宽度
	var height = $("#classify").height(); //获取单元格高度
	
	if (canvas.getContext) {
		var ctx = canvas.getContext("2d");

		ctx.fill();
		ctx.lineWidth = 1; //斜线的宽度
		ctx.strokeStyle = "#BBB"; //斜线的颜色
		ctx.beginPath();
		ctx.moveTo(0, 0); //斜线开始的坐标
		ctx.lineTo(width, height); //斜线结束的坐标
		ctx.stroke();
		ctx.closePath();
		
		document.getElementById("classify").style.backgroundImage = "url('" + ctx.canvas.toDataURL() + "')";
		document.getElementById("classify").style.background.attachment = "fixed";
	}
}

5.主要思路
获取单元格的宽度和高度,利用相对与单元格的坐标,连接两点划线。
可以参考教程:http://www.runoob.com/html/html5-canvas.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值