在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
jquery插件实现仪表盘,供大家参考,具体内容如下 做了个简易的仪表盘,就是很常见的那种码表,实现没啥困难,就是需要算一点点位置 实现效果代码部分*{ margin: 0; padding: 0; } .rel{ display: flex; justify-content:center; align-items:center; position: relative; } .bp{ border-radius:50% ; border: 1px solid lightgray; position:relative; display: flex; justify-content: center; align-items: center; transform: rotate(-45deg); } .kd{ position:absolute; width: 100%; font-size: 12px; } .point{ background-color:lightgray; height: 100px; width: 20px; border-radius:100%; transform: rotate(90deg); transform-origin:10px 0px; z-index: 9; position: absolute; transition: all 0.5s; } .kb{ position: absolute; bottom: 20px; font-size: 24px; color: gray; transition: all 0.5s; } <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>做个仪表盘</title> <script src="js/jquery-3.4.1.min.js"></script> <script src="js/zgybp.js"></script> <link href="css/zgybp.css" rel="stylesheet" type="text/css" /> <style> #div{ border: 1px solid lightgray; width: 90%; height: 400px; margin: 20px auto; } </style> </head> <body> <div id="div"></div> </body> </html> <script> var temp = zgybp("div"); setInterval(function(){ var f = Math.floor(Math.random()*101); temp.load(f); },700) </script> var zgybp = function(id){ var $id = $("#"+id); $id.addClass("rel"); var a = $id.width()>$id.height()?$id.height():$id.width(); $bp = $("<div class='bp'></div>"); $bp.appendTo($id); $bp.css({ "width":a, "height":a }) //绘制刻度,只绘制3/4 270/100=2.7,每一个刻度都是2.7 for(var i =100;i>=0;i--){ $kd = $("<div class='kd'><span class='txt'>-</span></div>"); if(i%5==0){ $kd.find('.txt').text(i) } $kd.appendTo($bp); $kd.css("transform","rotate("+(i*2.7)+"deg)"); } $point = $("<div class='point'></div>") $point.appendTo($bp) $point.css({ "left":a/2, "top":a/2 }) $kb = $("<div class='kb'>0</div>"); $kb.appendTo($id) //然后将表盘转1/8的角度,就差不多了 return{ $id:$id, $bp:$bp, $point:$point, $kb:$kb, load:function(f){ var that = this; f = f<0?0:f>100?100:f; var temp = parseInt(f)*2.7; that.$point.css({ "transform":"rotate("+(90+temp)+"deg)" }) that.draw(f); }, draw:function(f){ var that =this; that.$kb.text(f); } } } 实现思路
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持极客世界。 |
请发表评论