更改lib jquery.knob.js的元素大小

时间:2012-12-18 09:32:32

标签: javascript jquery

我有page

按下按钮后,您会看到lib jquery.knob.js的元素(圆圈) 我想要改变圆圈大小,我写了这段代码:

<div style="float:left; width:255px; height:155px">
            <input class="knob" data-fgColor="#9dc806" data-cgColor="black" data-bgColor="#7d7d7d" data-tickColor="black" data-thickness=".25" data-readOnly=true value="<?php echo $percent; ?>">
        </div>

但如果我改变div的宽度和高度,圆圈尺寸不会改变?

pb.php的所有代码页:

<?php
header('Content-Type: text/html; charset=utf-8');
include '../connect.php';
include '../ProcessingMySQL.php';
$mysqli = new ProcessingMySQL($hostname, $user_name, $password, $db_name);
$site = $_POST['sites'];
$percent = $mysqli->getPercentTopQuery($site);
?>

<html>
    <head>
    <style type="text/css">
        .knob{color:#000000 !important;}
    </style>

        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
        <script src="js/jquery.knob.js"></script>
        <script>
            $(function() {
                $(".knob").knob();
                var val,up=0,down=0,i=0
                    ,$idir = $("div.idir")
                    ,$ival = $("div.ival")
                    ,incr = function() { i++; $idir.show().html("+").fadeOut(); $ival.html(i); }
                    ,decr = function() { i--; $idir.show().html("-").fadeOut(); $ival.html(i); };
                $("input.infinite").knob(
                                    {
                                    'min':0
                                    ,'max':20
                                    ,'stopper':false
                                    ,'change':function(v){
                                                if(val>v){
                                                    if(up){
                                                        decr();
                                                        up=0;
                                                    }else{up=1;down=0;}
                                                }else{
                                                    if(down){
                                                        incr();
                                                        down=0;
                                                    }else{down=1;up=0;}
                                                }
                                                val=v;
                                            }
                                    }
                                );     
                                $('.knob').val($('.knob').val() + '%');     
             });
        </script>
        <style>
            h2{color:#87CEEB;font-family:'Georgia';}
        </style>
    </head>
    <body>
        <h1>Процент запросов в топе для сайта <?php echo $site; ?></h1>
        <div style="float:left; width:255px; height:155px">
            <input class="knob" data-fgColor="#9dc806" data-cgColor="black" data-bgColor="#7d7d7d" data-tickColor="black" data-thickness=".25" data-readOnly=true value="<?php echo $percent; ?>">
        </div>

    </body>
</html>

1 个答案:

答案 0 :(得分:1)

<div style="float:left; width:255px; height:155px">
            <input class="knob" data-fgColor="#9dc806" data-cgColor="black" data-bgColor="#7d7d7d" data-tickColor="black" data-thickness=".25" data-readOnly=true data-width="255" value="<?php echo $percent; ?>">
        </div>

尝试将data-width="width_of_circle"属性添加到input.knob。据我所知,这就是你如何控制圆的宽度。与上面的代码一样(宽度设置为255)