Is there a way to modify the background color of the altered path in the circular range slider?

Struggling with a function that should change the circle's background color when the slider is dragged to a specific path...


$(document).ready(function () {
   $("#circle").append('<canvas id="slideColorTracker" class="slideColor"></canvas>');
   var canvas = document.getElementById("slideColorTracker");
   var context = canvas.getContext('2d');
   var $circle = $("#circle"),
   $handler = $("#handler"),
   $p = $("#test").val(),
   handlerW2 = $handler.width() / 2,
   radius = ($circle.width()/2)+10,
   offset = $circle.offset(),
   elementPos = { x: offset.left, y: offset.top },
   mHold = 0,
   PI = Math.PI / 180
   $handler.mousedown(function () {
       mHold = 1;             
       var dim = $("#slideColorTracker");
       if ($(".slideColor").length > 1) {
           $("#slideColorTracker").remove();
       }
   });

   $(document).mousemove(function (e){
       move(e);
   }).mouseup(function () { mHold = 0 });

   function move(e) {
       if (mHold) {
           debugger
           var deg = 180;
           var startAngle = 4.72;
           var mousePos = { x: e.pageX - elementPos.x, y: e.pageY - elementPos.y }
           var atan = Math.atan2(mousePos.x - radius, mousePos.y - radius);
           var deg = -atan / PI + 180;                   
           var percentage = (deg * 100 / 360) | 0;
           var endAngle = percentage;
           var X = Math.round(radius * Math.sin(deg * PI)),
           Y = Math.round(radius * -Math.cos(deg * PI));
           var cw = X + radius - handlerW2 - 10; 
           var ch = Y + radius - handlerW2 - 10;
           $handler.css({
               left: X + radius - handlerW2 - 10,
               top: Y + radius - handlerW2 - 10,
           })
           context.beginPath();
           context.arc(($circle.width() / 2), ($circle.height() / 2), radius+20, startAngle, endAngle, false);
           context.lineWidth = 15;
           context.strokeStyle = 'black';
           context.stroke();
           $("#test").val(percentage);
           $circle.css({ borderColor: "hsl(200,70%," + (percentage * 70 / 100 + 30) + "%)" });
       }
   }
});

No plugin usage desired! Your expertise in jQuery would be greatly appreciated since I am still new to it!

Answer №1

The $controller isn't responsive for me unless I modify it to the following:

$controller.css({
    left: position.x,
    top: position.y,
    position:'absolute'
})

Once dragged beyond $circle.diameter / 2, it does execute the stroke accurately.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The error message [jsonFlickrApi is not defined] in JavaScript is indicating that the

Upon calling a FLickrAPI, the returned xmlhttp.responseText appears as follows: jsonFlickrApi({"photos":{"page":1, "pages":200, "perpage":100, "total":"19934", "photo":[{"id":"7315581986", "owner":"62691288@N00", "secret":"504915125a", "server":"7090", ...

Tips for toggling the visibility of a <div> element using PHP code inside

I'm having trouble with a dropdown list that is supposed to show/hide some divs containing PHP files. However, when I try to toggle the visibility of the divs using the dropdown list, it doesn't seem to work as expected. Can anyone help me figure ...

Developing a Generic API Invocation Function

I'm currently working on a function that has the capability to call multiple APIs while providing strong typing for each parameter: api - which represents the name of the API, route - the specific route within the 'api', and params - a JSON ...

JQuery retrieves the text content without taking into account the class

I'm struggling with my code and encountering an issue fetching text while excluding the menu-list-count class which displays a value next to the text. Here's what I've attempted: var mailfolder = $(this).not('[class="menu-list-cou ...

Implementing tether in webpack: A step-by-step guide

My webpack application, which I am using with Laravel Elixir, includes a 'bootstrap.js' file for initializing all libraries. Here is the content of the file: window._ = require('lodash'); /** * We'll load jQuery and the Bootstra ...

Automatically submitting a form in React.js based on certain conditions being met

Does anyone have experience with React login and register form buttons that trigger Redux actions? I'm facing an issue where both actions are being dispatched at the same time when certain conditions are met. Here is my code snippet: const LoginPage ...

What is the best way to extract information from a JavaScript page when the content is identified by a reference?

If you're looking for the website, you can visit . It's primarily in Chinese, but that may not be relevant to the topic at hand. Currently, I am able to extract all the content from this page and now I'm interested in moving on to the next ...

Suggestions for enhancing my HTML form using CSS

My school assignment involves creating a webpage. Here are the initial design concepts I have come up with: Click here for image This is what I have implemented so far: Click here for image What else do I need to add? <!DOCTYPE html> <html la ...

Passing Arguments to a Shared JS File

Is it possible to reduce code duplication by creating a common JS file for multiple datatables in my application? All Datatables will share the same theme, with only variations in data. For example, consider this script: var oTable = $('#Manag ...

Enhancing the security of various components by utilizing secure HTTP-only cookies

Throughout my previous projects involving authentication, I have frequently utilized localstorage or sessionstorage to store the JWT. When attempting to switch to httpOnly secure cookies, I encountered a challenge in separating the header component from th ...

How can I craft a customized lightbox with dynamically generated content?

I am currently developing a Twitter fetcher application and have encountered some issues with the scrolling functionality, particularly due to oversized images. I would like to implement image restrictions similar to what Twitter uses. https://i.sstatic.n ...

Enhancing Function Calls for Better Performance in V8

Is V8 capable of optimizing repeated function calls with identical arguments? For instance, in the code snippet below, Variance is invoked twice with the same arguments. var Variance = require('variance'); function summary(items) { ...

What is the process for utilizing GruntFile.coffee and package.json to extract or create the Lungo.js example files?

I want to experiment with the Lungo.js examples found here: https://github.com/tapquo/Lungo.js. However, when I try to run the index.html in the example directory, it seems like the components and package directories are empty. Although these directories d ...

What is the best way to adjust the height of the second column downwards?

I am trying to achieve a 2-column layout with both columns at the same height. This is how it currently appears: And this is how I want it to be: Here is my code snippet: html { background-color: lightblue; font-family: Tahoma, Geneva, sans-serif ...

What is the method for resolving circular references using double closures?

Recently, I came across an article discussing how circular references can lead to memory leaks in internet explorer (IE). The article presented an example involving closures nested within each other to demonstrate how a circular reference could occur: fun ...

Show drawer when modal is open in React Native

Currently, I am working on a project in react-native and facing an issue where the modal is appearing over the drawer navigator. Despite trying to adjust the zIndex property, it has not been effective. Details of my modal: <Modal visible={isVisible} ...

The d3 drag functionality is only active when the axis ticks are selected

Currently, I am developing a unique package that combines Angular and D3 (v3) and my main focus is on integrating D3's dragging feature into the package. Although I am very close to achieving success, there is a minor bug that I need to address. When ...

Ajax request causing bootstrap success message to have shorter visibility

I encountered an issue with my ajax form that retrieves data using the PHP post method. Instead of utilizing the alert function in JavaScript, I decided to use a bootstrap success message. However, there is a problem as the message only appears for less th ...

Observing the occurrences of JavaScript events

Is there a way to track all JavaScript events in the browser? Such as, identifying the functions that have been executed and the parameters that have been passed in each JS file? I'm dealing with some obfuscated code and I'm looking to determine ...

Set the value of the div element by extracting it from the JSON response

There is a div with an ID generated in PHP within a loop. <div align="left" id="BalBox<?php echo $row['pid']; ?>" class="text_balance">Balance: </div> where pid can be 1, 2, or 3 etc Now, I have the following JSON data. ...