当前位置:网站首页>客户评分控件
客户评分控件
2022-08-02 03:22:00 【cjx177187】
五角星评分控件

<body>
<style>
#box {
border: 1px solid black;
margin: 100px 0 0 100px;
width: 510px;
height: 100px;
position: absolute;
}
</style>
<h1>点亮小星星:</h1>
<div id="box"></div>
<script>
//画五角星
//1.利用圆形画五角星,在圆上找均匀分布的五个点
//2.利用三角函数算出每个点的坐标,作为连线的坐标
//3.将五个点两两间隔连接起来,形成五角星。
Object.prototype.start = function (x, y, r, color = "gray", ancolor = "yellow") {
this.beginPath()
var arr = []
var deg = Math.PI / 180
for (let i = 0; i < 5; i++) {
//1.利用圆形画五角星,在圆上找均匀分布的五个点
//2.利用三角函数算出每个点的坐标,作为连线的坐标
var x1 = x + Math.cos((72 * i - 90) * deg) * r
var y1 = y + Math.sin((72 * i - 90) * deg) * r
arr.push(x1, y1)
}
//3.将五个点两两间隔连接起来,形成五角星。
this.moveTo(arr[0], arr[1])
this.lineTo(arr[4], arr[5])
this.lineTo(arr[8], arr[9])
this.lineTo(arr[2], arr[3])
this.lineTo(arr[6], arr[7])
this.lineTo(arr[0], arr[1])
this.fillStyle = color
this.fill()
// this.stroke()
}
//封装一个canvas函数,在盒子里面添加一个人canvas根据盒子的宽高来决定五角星的大小
Object.prototype.canvas = function (n, color) {
var canvas = document.createElement("canvas")
var pen = canvas.getContext("2d")
var r = this.offsetHeight / 2
canvas.heigth = r * 2
canvas.width = (this.offsetHeight + 4) * 5
this.appendChild(canvas)
//判断点亮五角星的个数,将要改变的五角星填充为黄色
for (let i = 0; i < 5; i++) {
if (i < n) {
pen.start(r + r * 2 * i, r, r, "yellow")
} else {
pen.start(r + r * 2 * i, r, r, color)
}
}
}
</script>
<script>
var box = document.querySelector("#box")
box.canvas()
//给box绑定移动事件,通过事件的属性和弹性盒子的属性来计算出鼠标移动到那个五角星,将前面所有的五角星的填充颜色变为黄色
box.onmousemove = function (el) {
var n = Math.ceil((el.clientX - this.offsetLeft) / (this.offsetHeight + 4))
this.innerHTML = " "
this.canvas(n)
}
</script>
边栏推荐
- A senior test engineer asked me these questions as soon as the interview came
- 小程序组件总结
- docker 安装 sqlserver中的坑点
- IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boo
- @ApiModel 和 @ApiModelProperty
- 【面试】失败的一次面试
- Source Insight 使用教程(2)——常用功能
- Chapter 10 Clustering
- 网站与服务器维护怎么做?
- 基本运算符
猜你喜欢

Redis简单学习笔记

UserWarning:火炬。meshgrid:在以后的版本中,它将被要求通过索引ing argu

Chemical reagent Phospholipid-polyethylene glycol-hydroxyl, DSPE-PEG-OH, DSPE-PEG-Hydroxyl, MW: 5000

parser = argparse.ArgumentParser()解析

【深度学习】从LeNet-5识别手写数字入门深度学习

语义分割标签即像素值的巨坑,transforms.ToTensor()的错误使用

Redis simple study notes

Scientific research reagent DMPE-PEG-Mal dimyristoylphosphatidylethanolamine-polyethylene glycol-maleimide

科研试剂DMPE-PEG-Mal 二肉豆蔻酰磷脂酰乙醇胺-聚乙二醇-马来酰亚胺

远程调试、无cuDnn、自定义模块无法导入问题记录
随机推荐
C语言 0长度数组/柔性数组
磷脂-聚乙二醇-酰肼,DSPE-PEG-Hydrazide,DSPE-PEG-HZ,MW:5000
DSPE-PEG-PDP, DSPE-PEG-OPSS, phospholipid-polyethylene glycol-mercaptopyridine supply, MW: 5000
Monaco Editor 的基本用法
ModuleNotFoundError No module named 'xxx' possible solutions
我的两周年创作纪念日
最新,每天填坑,Jeston TX1 精卫填坑,第一步:刷机
【博学谷学习记录】超强总结,用心分享 | 软件测试 接口测试基础
cross-domain problem solving
@Autowired与@Resource区别
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boo
3 minutes to take you to understand WeChat applet development
C语言 内联函数
The difference between the knowledge question and answer session with the knowledge
Chapter 10 Clustering
getattr()函数解析
Phospholipid-polyethylene glycol-targeted neovascularization targeting peptide APRPG, DSPE-PEG-APRPG
np.isnan()
How to check whether a table is locked in mysql
【程序人生】做了多年的运维,靠什么转行拿下12K+年终奖的薪资?