时间:2021-05-26
本文实例为大家分享了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; top: 0; left: 125px; text-align: center; font-size: 16px; transform-origin: bottom center; } .con1 { width: 400px; height: 400px; 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; 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>以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
今天学习jQuery的选择器:jQuery选择器分为基本选择器、层次选择器、过滤选择器、表单选择器。基本选择器:id,class,标签名,*,元素组合(div,
本文实例讲述了jQuery内容选择器与表单选择器。分享给大家供大家参考,具体如下:内容选择器jQuery内容过滤选择器的过滤规则主要运用在DOM元素所包含的子元
本文实例讲述了js实现可得到不同颜色值的颜色选择器。分享给大家供大家参考。具体实现方法如下:复制代码代码如下:js颜色选择器,可得到不同的颜色值variW='7
CSS组合选择符包括各种简单选择符的组合方式。在CSS3中包含了四种组合方式:后代选择器(以空格分隔)子元素选择器(以大于号分隔)相邻兄弟选择器(以加号分隔)普
可能大家见过很多使用jquery/js开发的颜色选择器,今天这里我们将使用HTML5技术来自己实现一个更棒的颜色选择器。希望大家喜欢!复制代码代码如下:RGBR