0

i am using jquery knob and in my use case I want the cursor width in percentage so that when the width is 100% cursor occupies the whole circle, however it only takes numeric value as input, what are my options ?

   $(function() {
        $(".dial1").knob({
            'bgColor': 'green',
            "skin":"tron",
            'fgColor': 'red',
            'cursor': '100'
        });
    });

The cursor fills the whole circle if I give it a value of 320.

Dev R
  • 1,892
  • 1
  • 25
  • 38

2 Answers2

0

As far as I can tell your only option is to change the source code of the jQuery plugin. The width in pixels is hardcoded in the plugin, for example on line 153 it says:

    this.$c = $('<canvas width="' +
                        this.o.width + 'px" height="' +
                        this.o.height + 'px"></canvas>');

The this.o.width value is what you set as 'cursor': '100'.

You can either change the plugin by making the px to % or removing the px and adding whatever value you want it to be like for the example on line 153:

    this.$c = $('<canvas width="' +
                        this.o.width + " height="' +
                        this.o.height + "></canvas>');

And than in the init do something like :

$(function() {
    $(".dial1").knob({
        'bgColor': 'green',
        "skin":"tron",
        'fgColor': 'red',
        'cursor': '100%'
    });
});
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
putvande
  • 15,068
  • 3
  • 34
  • 50
0

I am using a workaround where in if I want x percentage to show and total is y then I am doing (x/y)*320 it gives the cursor width in percentage since x is dynamic the cursor keeps on filling the circle as this value increases. Since this is a very specific issue and I don't expect any other answer coming soon am marking this as the answer.

Dev R
  • 1,892
  • 1
  • 25
  • 38