js实现圆形菜单选择器
作者:liuhao9999 时间:2023-09-23 19:50:54
本文实例为大家分享了js实现圆形菜单选择器的具体代码,供大家参考,具体内容如下
代码:
<head>
<style>
.mask{
position: absolute;
width: 502px;
height: 252px;
left:300px;
top:350px;
background: white;
z-index: 999;
}
.con {
width: 500px;
height: 500px;
overflow: hidden;
position: absolute;
border-radius: 100%;
border: 1px solid black;
user-select: none;
cursor: pointer;
left: 300px;
top: 100px;
}
.con>div {
position: absolute;
width: 250px;
height: 250px;
/* border:1px solid black; */
top: 0;
left: 125px;
text-align: center;
font-size: 16px;
transform-origin: bottom center;
}
.con1 {
width: 400px;
height: 400px;
/* background: yellow; */
overflow: hidden;
position: absolute;
border-radius: 100%;
border: 1px solid black;
user-select: none;
cursor: pointer;
left: 350px;
top: 150px;
}
.con1>div {
position: absolute;
width: 200px;
height: 200px;
/* border:1px solid black; */
top: 0;
left: 100px;
text-align: center;
font-size: 16px;
transform-origin: bottom center;
}
</style>
<meta name="viewport"
content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
</head>
<body>
<div class="mask"></div>
<div class="con">
</div>
<div class="con1">
</div>
<script>
conRender();
conRender1();
function conRender() {
var con = document.querySelector(".con");
var len = 16;
var deg = 360 / len;
for (var i = 0; i < len; i++) {
var dom = document.createElement("div");
dom.style.transform = "rotate(-" + i * deg + "deg)";
dom.innerHTML = "财务管理" + i;
dom.setAttribute("index", i)
con.appendChild(dom)
}
var mouseDown = false;
var startX = 0;
var startY = 0;
var endX = 0;
var endY = 0;
var rotate = 0;
con.addEventListener("mousedown", function (e) {
mouseDown = true;
startX = e.pageX;
startY = e.pageY;
}, false);
con.addEventListener("mousemove", function (e) {
if (mouseDown) {
endX = e.pageX;
endY = e.pageY;
var distance = Math.sqrt(Math.pow((endX - startX), 2) + Math.pow((endY - startY), 2))
if (endX - startX < 0 || endY - startY < 0) {
distance = -distance
}
rotate += distance
con.style.transform = "rotate(" + (rotate / 4) + "deg)";
startX = e.pageX;
startY = e.pageY;
var index = Math.round((rotate / 4) / deg);
var cons = document.querySelectorAll(".con>div")
for (var i = 0, len = cons.length; i < len; i++) {
cons[i].style.color = "black"
}
document.querySelector("div[index=\"" + index % len + "\"]").style.color = "red"
document.querySelector(".con1").style.transform = "rotate(" + (rotate) + "deg)";
}
}, false);
document.addEventListener("mouseup", function (e) { mouseDown = false; }, false);
}
function conRender1() {
var con = document.querySelector(".con1");
var len = 13;
var deg = 360 / len;
for (var i = 0; i < len; i++) {
var dom = document.createElement("div");
dom.style.transform = "rotate(-" + i * deg + "deg)";
dom.innerHTML = "财务管理" + i;
dom.setAttribute("index1", i)
con.appendChild(dom)
}
var mouseDown = false;
var startX = 0;
var startY = 0;
var endX = 0;
var endY = 0;
var rotate = 0;
con.addEventListener("mousedown", function (e) {
mouseDown = true;
startX = e.pageX;
startY = e.pageY;
}, false);
con.addEventListener("mousemove", function (e) {
if (mouseDown) {
endX = e.pageX;
endY = e.pageY;
var distance = Math.sqrt(Math.pow((endX - startX), 2) + Math.pow((endY - startY), 2))
if (endX - startX < 0 || endY - startY < 0) {
distance = -distance
}
rotate += distance
con.style.transform = "rotate(" + (rotate / 4) + "deg)";
startX = e.pageX;
startY = e.pageY;
var index = Math.round((rotate / 4) / deg);
var cons = document.querySelectorAll(".con1>div")
for (var i = 0, len = cons.length; i < len; i++) {
cons[i].style.color = "black"
}
document.querySelector("div[index1=\"" + index % len + "\"]").style.color = "red"
}
}, false);
document.addEventListener("mouseup", function (e) { mouseDown = false; }, false);
}
</script>
</body>
</html>
来源:https://blog.csdn.net/liuhao9999/article/details/110470057
标签:js,菜单,选择器
0
投稿
猜你喜欢
Python爬虫设置ip代理过程解析
2021-05-27 15:08:30
MySql中如何使用 explain 查询 SQL 的执行计划
2024-01-15 10:25:01
Typescript3.9 常用新特性一览(推荐)
2024-04-18 10:56:16
python中类变量与成员变量的使用注意点总结
2022-01-08 03:39:51
解决pycharm导入本地py文件时,模块下方出现红色波浪线的问题
2023-11-11 10:38:14
安装dbus-python的简要教程
2021-09-07 10:09:43
CentOS 6.X系统下升级Python2.6到Python2.7 的方法
2023-01-05 03:36:18
sqoop如何指定pg库的模式(方法详解)
2022-09-30 02:52:47
python GUI库图形界面开发之PyQt5控件QTableWidget详细使用方法与属性
2022-08-13 22:06:58
python实现通过队列完成进程间的多任务功能示例
2022-06-25 03:49:27
numpy.random.choice()函数详解
2023-04-30 09:46:03
MySQL中SQL的单字节注入与宽字节注入
2009-03-25 14:49:00
MySQL命令行中给表添加一个字段(字段名、是否为空、默认值)
2024-01-16 12:47:36
Python使用configparser读取ini配置文件
2023-11-02 04:48:22
一个轻量级的XHTML右键菜单[支持IE和firefox]
2024-04-19 10:58:32
Matlab实现新冠病毒传播模拟效果
2022-01-23 00:01:28
Python 去除字符串中指定字符串
2023-04-20 23:44:53
Zabbix实现微信报警功能
2021-10-17 04:40:05
12个对网页设计师非常有用的图片优化工具[译]
2009-09-22 14:29:00
JavaScript字符串对象toLowerCase方法入门实例(用于把字母转换为小写)
2024-05-08 10:10:47