css3实现雷达图

效果图:

gif图:



代码:

<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">   
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/>   
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />       
<title>Radar</title>
<style type="text/css">
html {height: 100%;}
body {width: 100%;height: 100%;position: relative;padding: 0;margin: 0;}
.m-wrapper {position: relative;left: 50%;top: 50%;width: 600px;height: 600px;-webkit-transform: translate(-50%, -50%);transform: translate(-50%, -50%);border-radius: 50%;border: 1px solid #dddddd;overflow: hidden;text-align: center;}
.m-center{display: inline-block;position: absolute;margin: auto;top: 0; bottom: 0;left: 0;right: 0;}
.m-divison1{width: 400px;height: 400px;border: 1px solid #dddddd;border-radius: 50%;}
.m-divison2{width: 200px;height: 200px;border: 1px solid #dddddd;border-radius: 50%;background-color: #ffffff;z-index: 9;}
.m-circle {width: 180px; height: 180px;border-radius: 90px;overflow: hidden;}
.m-circle-loading {position: absolute;top: 0;left:0;width: 50%; height: 100%;
    background: -webkit-linear-gradient(bottom, rgba(255, 255, 255, 0), #6699ff);
    background: -moz-linear-gradient(top, rgba(255, 255, 255, 0), #6699ff);   
    background: linear-gradient(to top, rgba(255, 255, 255, 0), #6699ff);
    -webkit-animation: radar-beam 5s infinite;
    animation: radar-beam 5s infinite;
    -webkit-animation-timing-function: linear;
    animation-timing-function: linear;
    -webkit-transform-origin: center right;
    transform-origin: center right;border-top-left-radius: 90px;border-bottom-left-radius:90px;}
.m-circle-loading-radius{position: absolute;top: 0;right: 0;width: 10px;height: 10px;background: #6699ff;border-top-right-radius: 50%;border-bottom-right-radius: 50%;-webkit-transform: translateX(5px);transform: translateX(5px);}
.m-center-text{width: 160px; height: 160px;line-height: 160px;font-size: 24px; border-radius: 50%;background: #ffffff;z-index: 99;}
.m-radar {display: block;position: absolute;top: 0;left: 0;width: 300px;height: 300px;
    background-image: -webkit-linear-gradient(44deg, rgba(255, 255, 255, 0) 50%, #cccccc 100%);
    background-image: linear-gradient(44deg, rgba(255, 255, 255, 0) 50%, #cccccc 100%);
    -webkit-animation: radar-beam 5s infinite;
    animation: radar-beam 5s infinite;
    -webkit-animation-timing-function: linear;  
    animation-timing-function: linear;
    -webkit-transform-origin: bottom right;
    transform-origin: bottom right;border-radius: 100% 0 0 0;}
.m-breathe-btn {display: inline-block;position:absolute; width:10px; height:10px;border:1px solid transparent; border-radius:5px; color:#fff; font-size:20px; text-align:center;cursor:pointer; box-shadow:0 1px 2px rgba(0,0,0,.3); overflow:hidden;background-image: -webkit-gradient(linear, left top, left bottom, from(#6cc3fe), to(#21a1d0));-webkit-animation-timing-function: ease-in-out;-webkit-animation-name: breathe;-webkit-animation-duration: 2700ms;-webkit-animation-iteration-count: infinite;-webkit-animation-direction: alternate;}
@-webkit-keyframes breathe {
  0% { opacity: .2; box-shadow:0 1px 2px rgba(255,255,255,0.1);}
  100% { opacity: 1; border:1px solid rgba(59,235,235,1); box-shadow:0 1px 30px rgba(59,255,255,1);}
}
@keyframes breathe {
  0% { opacity: .2; box-shadow:0 1px 2px rgba(255,255,255,0.1);}
  100% { opacity: 1; border:1px solid rgba(59,235,235,1); box-shadow:0 1px 30px rgba(59,255,255,1);}
}
@-webkit-keyframes radar-beam {
  0% {-webkit-transform: rotate(0deg);transform: rotate(0deg);}
  100% {-webkit-transform: rotate(360deg);transform: rotate(360deg);}
}
@keyframes radar-beam {
  0% {-webkit-transform: rotate(0deg);transform: rotate(0deg);}
  100% {-webkit-transform: rotate(360deg);transform: rotate(360deg);}
}

</style>
</head>
<body>
<div class="m-wrapper">
    <div class="m-center m-divison1">
        <div class="m-center m-divison2">
            <div class="m-center m-circle">
                <div class="m-center m-center-text" id="m-center-text">3.64k</div>
                <div class="m-circle-loading">
                    <span class="m-circle-loading-radius"></span>
                </div>
            </div>
        </div>
    </div>
    <div class="m-radar"></div>
</div>
<script src="https://cdn.bootcss.com/jquery/1.9.0/jquery.js"></script>
<script>
$(function () {
    var dom = {
        centerText: $('#m-center-text')
    };
    var action = {
        initPage: function () {
            var height = $(document).height();
            var width = $(document).width();
            var count = 0;
            var myVar = setInterval(function () {
                var top = Math.floor(Math.random() * (height - 100) + 100);
                var left = Math.floor(Math.random() * (width - 200) + 100);
                var breatheBtn = $('<div class="m-breathe-btn js-breathe-btn"></div>');
                breatheBtn.css({top: top, left: left});
                $(document.body).append(breatheBtn);             
                var text = (Math.floor(Math.random() * 300) + 200) / 100 + 'k';
                dom.centerText.text(text);
                count++;
                if (count >= 10) {
                    //clearInterval(myVar);
                    var totalBreatheBtn = $('.js-breathe-btn');
                    var length = totalBreatheBtn.length;
                    var index = Math.floor(Math.random() * length);
                    if (index < length) {
                        $(totalBreatheBtn[index]).remove();
                    }
                }   
            }, 1000); 
        }
    }
    var init = function () {
        action.initPage();
    }();
});
</script>
</body>
</html>





猜你喜欢

转载自blog.csdn.net/xutongbao/article/details/80931875