Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h2>Clock demo with predefined value</h2>
<input type="text" id="test-1" name="test-1" class="circle-range-select" value="10;360" data-boundry="10;360" data-min="0" data-max="360" data-unit="$">
<input type="text" id="test-2" name="test-2" class="circle-range-select" value="55;120" data-boundry="55;120" data-min="0" data-max="360" data-unit="$">
<input type="text" id="test-3" name="test-3" class="circle-range-select" value="240;300" data-boundry="240;300" data-min="0" data-max="360" data-unit="$">
              
            
!

CSS

              
                input.circle-range-select{display:none}.circle-range-select-wrapper{position:relative;max-width:100%;width:10em;height:10em;margin:1em;border-radius:50%;border:.8em solid #ccc;padding:0!important;cursor:default}.circle-range-select-wrapper .handle{position:absolute;z-index:2;width:0;height:0;border:0;padding:0;cursor:pointer}.circle-range-select-wrapper .handle:before{content:'';position:absolute;z-index:3;top:-1em;left:-1em;height:2em;width:2em;border-radius:50%;background:#000}.circle-range-select-wrapper .selected-range{position:absolute;z-index:1;color:#0ff}.circle-range-select-wrapper .values{position:absolute;z-index:2;top:50%;margin-top:-.5em;width:100%;font-size:.85rem;text-align:center}
              
            
!

JS

              
                (function (root, factory) {
  var $ = root.jQuery;

  if (typeof define === 'function' && define.amd) {
    // AMD
    if ($) {
      define([], factory.bind(null, $));
    }
    else {
      define(['jquery'], factory);
    }
  } else if (typeof exports === 'object') {
    // Node, CommonJS-like
    if ($) {
      module.exports = factory($);
    }
    else {
      module.exports = factory(require('jquery'));
    }
  } else {
    // Browser globals (root is window)
    if ($) {
      factory($); // no global needed as we store it as a jQuery plugin on jQuery.fn
    }
    else {
      throw 'Missing required jQuery dependency';
    }
  }
}(this, function ($) {
  var isDragging = false;
  var $currentHandle = null;

  function drawCircle($container, degreeStart, degreeEnd) {
    var
      $canvas = $container.find('canvas'),
      canvas = $canvas[0]
    ;

    var outerWidth = $container.outerWidth();
    var innerWidth = $container.innerWidth();
    var borderWidth = outerWidth - innerWidth;
    $canvas.css('left', borderWidth*-1);
    $canvas.css('top', borderWidth*-1);


    var radius = (outerWidth - borderWidth / 2) / 2;
    canvas.width = outerWidth + borderWidth;
    canvas.height = canvas.width;
    var context = canvas.getContext('2d');
    context.clearRect(0, 0, canvas.width, canvas.height);
    context.beginPath();



    context.arc(canvas.width / 2, canvas.width / 2,radius, degreesToRadians(degreeStart)-Math.PI/2, degreesToRadians(degreeEnd)-Math.PI/2, false);
    context.lineWidth = borderWidth/2;
    context.strokeStyle = $canvas.css('color');
    context.stroke();
  }

  function degreesToRadians (degrees) {
    return degrees * (Math.PI/180);
  }

  function updateWidget($container) {
    var $handles = $container.find('.handle');
    var $handle1 = $container.find('.handle1');
    var $handle2 = $container.find('.handle2');

    var outerWidth = $container.outerWidth();
    var innerWidth = $container.innerWidth();
    var borderWidth = (outerWidth - innerWidth) / 2;
    var handleWidth = $handles.outerWidth();

    var radius = (outerWidth - borderWidth) / 2;

    var $input = $container.find('input');
    var minValue = $input.attr('data-min') || 0;
    var maxValue = $input.attr('data-max') || 360;
    var unit = $input.attr('data-unit') || '&deg;';
    var steps = maxValue - minValue
    var stepSize = 360/steps;

    $handles.each(function(idx, handle) {
      var $handle = $(handle);
      var value = $handle.attr('data-value');
      var deg = value*stepSize;

      var X = Math.round(radius + radius * Math.sin(deg*Math.PI/180));
      var Y = Math.round(radius + radius * -Math.cos(deg*Math.PI/180));
      $handle.css({ left: X, top: Y });
      $container.find($handle.attr('data-value-target')).html($handle.attr('data-value') + unit);
    });

    value1 = $handle1.attr('data-value');
    value2 = $handle2.attr('data-value');
    drawCircle($container, value1 * stepSize, value2 * stepSize);
    $input.val(value1+';'+value2).trigger('change');
  }

  function init($input) {
    var values = $input.val() || '0;0';
    values = values.split(';');
    var value1 = parseInt(values[0], 10);
    var value2 = parseInt(values[1], 10);

    $container = $('<div class="circle-range-select-wrapper"></div>');
    $input.wrap($container);
    $container = $input.parent();

    $container.append('<div class="handle handle1" data-value="' + value1 + '" data-value-target=".value1"></div>');
    $container.append('<div class="handle handle2" data-value="' + value2 + '" data-value-target=".value2"></div>');
    $container.append('<div class="values"><span class="value1"></span> - <span class="value2"></span></div>');
    $container.append('<canvas class="selected-range"></canvas>');

    updateWidget($container);

    $container.on('mousedown touchstart', '.handle', function(e) {
      isDragging = true;
      e.preventDefault();
      $currentHandle = $(e.target);
      $(document).one('mouseup touchend', function() {
        isDragging = false;
        $currentHandle = null;
      });
    });

    $(window).on('resize', updateWidget.bind(null, $container));
  }

  $(document).on('mousemove touchmove', function (e) {
    if (isDragging) {
      var $container = $currentHandle.closest('.circle-range-select-wrapper');
      var radius = $container.width() / 2;

      if (!e.offsetX && e.originalEvent.touches) {
        // touch events
        var targetOffset = $(e.target).offset();
        e.offsetX = e.originalEvent.touches[0].pageX - targetOffset.left;
        e.offsetY = e.originalEvent.touches[0].pageY - targetOffset.top;
      }
      else if(typeof e.offsetX === "undefined" || typeof e.offsetY === "undefined") {
        // firefox compatibility
        var targetOffset = $(e.target).offset();
        e.offsetX = e.pageX - targetOffset.left;
        e.offsetY = e.pageY - targetOffset.top;
      }

      var mPos = {
        x: e.target.offsetLeft + e.offsetX,
        y: e.target.offsetTop + e.offsetY
      };

      var atan = Math.atan2(mPos.x - radius, mPos.y - radius);
      var deg = -atan / (Math.PI / 180) + 180; // final (0-360 positive) degrees from mouse position

      var $input = $container.find('input');
      var minValue = $input.attr('data-min') || 0;
      var maxValue = $input.attr('data-max') || 360;
      var steps = maxValue - minValue
      var stepSize = 360/steps;

      var value = Math.round(deg/stepSize);
      //if (value == maxValue) {
      //  value = minValue;
      //}
      var boundry = $input.attr("data-boundry"),
          boundryValue = boundry.split(";"),
          startBoundy = boundryValue[0],
          endBoundry = boundryValue[1];
      // if(value > 180){
      //   return;
      // }
      var currentValueOfSlider = $input.val();

      var values = $input.val() || '0;0';
      values = values.split(';');

      var startValue = parseInt(values[0], 10);
      var endValue = parseInt(values[1], 10);
      if($currentHandle.hasClass("handle1")){
        if( (value >= (endValue-10)) || (value <= startBoundy) ){
          return;
        }
      } else {
        if( (value <= (startValue+10)) || (value >= endBoundry) ){
          return;
        }
      }

      $currentHandle.attr('data-value', value);

      updateWidget($container);
    }
  });


  $.fn.lcnCircleRangeSelect = function() {
    return this.each(function() {
      init($(this));
    });

  };

}));
jQuery('#test-1').lcnCircleRangeSelect();
jQuery('#test-2').lcnCircleRangeSelect();
jQuery('#test-3').lcnCircleRangeSelect();
              
            
!
999px

Console