Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9258155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:19:26+00:00 2026-06-18T12:19:26+00:00

Is there any way to add angular gradient to jQuery knob plugin, so that

  • 0

Is there any way to add angular gradient to jQuery knob plugin, so that it starts from one color and along the arc, changes into another?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:19:28+00:00Added an answer on June 18, 2026 at 12:19 pm

    I digged the internet for a solution but no one ever tried this or posted a solution. Finally I am posting a Q&A. If anyone has a better solution, please share with us.

    During the initialization, I have overridden the draw method and checked for the attribute shaded=”true”. If it’s there, then a gradient is formed, starting from white and moving towards fgColor. To chose starting color other than white, set the attribute shadeColor=”#(color hex code)”.

    <input class="knob" value="95" autocomplete="off" data-readOnly=true data-fgColor="#FF0000" data-bgColor="transparent" shaded="1" shadeColor="#00FF00"/>
    <script>
        $(function(){
            $('.knob').knob({
                draw : function () {
                    var a = this.angle(this.cv)  // Angle
                    , sa = this.startAngle          // Previous start angle
                    , sat = this.startAngle         // Start angle
                    , ea                            // Previous end angle
                    , eat = sat + a                 // End angle
                    , r = 1;
    
                    this.g.lineWidth = this.lineWidth;
    
                    if(this.$.attr('shaded')){
                        var color1 = r ? this.o.fgColor : this.fgColor;
                        var color2 = this.$.attr('shadeColor') ? this.$.attr('shadeColor') : '#ffffff';
                        var grad = getGradient(color2, color1);
    
                        var saDeg = parseInt((sa * 180 / Math.PI) % 360);
                        var eatDeg = parseInt((eat * 180 / Math.PI) % 360);
    
                        for(var angle = saDeg;(angle % 360) != eatDeg;angle++){
                            sat = angle * (Math.PI / 180);
                            eat = (angle + 2) * (Math.PI / 180);
    
                            if(grad.color2[0] != grad.color1[0] && (angle + 1) % grad.steps[0] == 0){
                                grad.color1[0] += grad.adder[0];
                            }
                            if(grad.color2[1] != grad.color1[1] && (angle + 1) % grad.steps[1] == 0){
                                grad.color1[1] += grad.adder[1];
                            }
                            if(grad.color2[2] != grad.color1[2] && (angle + 1) % grad.steps[2] == 0){
                                grad.color1[2] += grad.adder[2];
                            }
    
                            color = '#' + toHex(grad.color1[0]) + toHex(grad.color1[1]) + toHex(grad.color1[2]);
    
                            this.g.beginPath();
                            this.g.strokeStyle = color;
                            this.g.arc(this.xy, this.xy, this.radius, sat, eat, false);
                            this.g.stroke();
                        }
                    } else {
                        this.g.beginPath();
                        this.g.strokeStyle = r ? this.o.fgColor : this.fgColor ;
                        this.g.arc(this.xy, this.xy, this.radius, sat, eat, false);
                        this.g.stroke();
                    }
    
                    return false;
                }
            });
        });
    
        function getGradient(color1, color2){
            var ret = new Object();
    
            ret.color1 = new Array();
            ret.color2 = new Array();
            ret.steps = new Array();
            ret.adder = new Array();
    
            color1 = color1.replace('#','');
            ret.color1[0] = parseInt(color1.slice(0,2), 16),
            ret.color1[1] = parseInt(color1.slice(2,4), 16),
            ret.color1[2] = parseInt(color1.slice(4,6), 16);
    
            color2 = color2.replace('#','');
            ret.color2[0] = parseInt(color2.slice(0,2), 16),
            ret.color2[1] = parseInt(color2.slice(2,4), 16),
            ret.color2[2] = parseInt(color2.slice(4,6), 16);
    
            ret.steps[0] = (ret.color1[0] == ret.color2[0])? 0 : parseInt(360 / Math.abs(ret.color1[0] - ret.color2[0])),
            ret.steps[1] = (ret.color1[1] == ret.color2[1])? 0 : parseInt(360 / Math.abs(ret.color1[1] - ret.color2[1])),
            ret.steps[2] = (ret.color1[2] == ret.color2[2])? 0 : parseInt(360 / Math.abs(ret.color1[2] - ret.color2[2])),
    
            ret.adder[0] = (ret.color1[0] > ret.color2[0])? -1 : 1;
            ret.adder[1] = (ret.color1[1] > ret.color2[1])? -1 : 1;
            ret.adder[2] = (ret.color1[2] > ret.color2[2])? -1 : 1;
    
            return ret;
        }
    
        function toHex(number){
            number = number.toString(16);
            if(number.length < 2){
                number = '0' + number;
            }
            return number;
        }
    </script>
    

    It draws a separate arc for each degree (with arc angle of 2 degrees instead of one for the sake of smoothness). The colors of arcs go through a transition from fgColor to shadeColor.

    The color mixing effect is like paint mixing rather than light mixing, so if you start from green and go towards red, you won’t get the yellow shade in the center. It would look cool with light mixing effect but don’t know how to do that exactly. Also it is not a well optimized code, it’s just a solution. Huge room for improvement..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to add reference from one winforms to another winforms?? There
are there any way to add new column to the table with JQuery plugin
i want to add one field in view from my module.Is there any way
Is there any way to add a custom class to the outer div that
Is there any way to add an event to the current thread that is
is there any way to add jquery ready() function to a code like this?
Is there any possible way to add swing into a shutdown hook (that is,
I Understand that Android it's open-source platform, So is there any way to add/modify
Is there any way to add one string to the end of another in
Is there any way to add an icon to a windows console application (that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.