码迷,mamicode.com
首页 > Web开发 > 详细

可自定义刻度jQuery进度条

时间:2015-09-02 01:56:15      阅读:262      评论:0      收藏:0      [点我收藏+]

标签:

可自定义刻度jQuery进度条是一款可以自定义进度条刻度圆点的数量,大小,颜色等属性,并且可以通过CSS来控制圆点的外观样式。效果图如下:

技术分享

在线预览    源码下载

实现的代码。

html代码:

<div class="htmleaf-container">
       <div id="container">
           <div class="padded">
               <div id="progressHolder"></div>
               <div id="progressReset">生成随机的风格</div>
           </div>
       </div>
   </div>
   <script src="js/jquery-2.1.1.min.js" type="text/javascript"></script>
   <script src="js/jquery.progressdots.js"></script>
   <script src="js/prism.js"></script>
   <script>
       $(document).ready(function () {
           createSpots(1);
           $("#progressReset").click(function (event) {
               event.preventDefault();
               createSpots(1);
           });
           function createSpots(num) {
               for (var i = 0; i < num; i++) {
                   options = {
                       dotSize: random(10, 20) + "px",
                       radius: random(1, 7) * 10 + "%"
                   };
                   randomHtml = "";
                   if (Math.random() < 0.5) {
                       options.randomColors = true;
                       randomHtml += "\n\trandomColors: " + options.randomColors + ", //use random colors";
                   }
                   else {
                       options.dotColor = randomColor();
                       randomHtml += "\n\tdotColor: ‘" + options.dotColor + "‘, //set dot color (#HEX)";
                   }
                   if (Math.random() < 0.3) {
                       options.progress = true;
                       options.percent = random(5, 100);
                       randomHtml += "\n\tprogress: true, //enable progress";
                       randomHtml += "\n\tpercent: " + options.percent + ", //set initial percentage";
                   } else {
                       options.numDots = random(3, 15);
                       randomHtml += "\n\tnumDots: " + options.numDots + ", //number of dots";
                   }
                   string = "$( ‘#progressBox‘ ).dottify({                       \n\tdotSize: ‘" + options.dotSize + "‘, //set size of dot" +
                           randomHtml +
                           "\n\tradius: ‘" + options.radius + "‘ //set dot corner radius               \n});";
                   var $container = $("<div class=‘swoopContainer‘></div>").data("setupString", JSON.stringify(string));
                   $("#progressHolder").append($container.hide());
                   $container.slideDown(function () {
                       $(this).css({ overflow: "hidden" });
                   });
                   $container.click(function () {
                       $(".swoopContainer").removeClass("selected");
                       $(this).addClass("selected");
                       $("#jsContents").html(JSON.parse($(this).data("setupString")));
                       Prism.highlightAll();
                   });
                   $container.dottify(options);
                   $("#jsContents").html(string);
                   Prism.highlightAll();
               }
               $(".swoopContainer").removeClass("selected");
               $(".swoopContainer").last().addClass("selected");
           }
           function randomColor() {
               return # + Math.floor(Math.random() * 16777215).toString(16);
           }
           function random(min, max) {
               return Math.floor(Math.random() * ((max - min) + min) + min);
           }
       });
   </script>

via:http://www.w2bc.com/article/60080

可自定义刻度jQuery进度条

标签:

原文地址:http://www.cnblogs.com/w2bc/p/4777407.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!