123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
                <header>
    <h2>Radial Slider</h2>
    <p>A radial slider, made with CSS3 and jQuery, Enjoy!</p>
    <p>By <a href="http://adrianquevedo.com" target="_blank">Adrian Quevedo</a></p>
    <footer class="footer">
      <p>© 2002 - 2011 Nintendo. The Legend of Zelda is a trademark of Nintendo. © 2011 Nintendo.</p>
    </footer>
  </header>

	<section>
		<div class="knob-slider">
			<div class="knob">
			  <p class="instructions">Drag the knob to see the illustrations</p>
			</div>
			<div class="knob-circle">
				<div class="circle c01"><img src="https://dl.dropboxusercontent.com/u/2402696/codepen-demos/radial-slider/assets/i/link-green.png" alt="Green Link"></div>
				<div class="circle c02"><img src="https://dl.dropboxusercontent.com/u/2402696/codepen-demos/radial-slider/assets/i/link-red.png" alt="Red Link"></div>
				<div class="circle c03"><img src="https://dl.dropboxusercontent.com/u/2402696/codepen-demos/radial-slider/assets/i/link-blue.png" alt="Blue Link"></div>
				<div class="circle c04"><img src="https://dl.dropboxusercontent.com/u/2402696/codepen-demos/radial-slider/assets/i/link-magenta.png" alt="Purple Link"></div>
			</div>
		</div>
	</section>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Shadows+Into+Light+Two);

html {
  background-color: #212121; }

a:link,
a:visited {
  color: white;
}

header {
  background-color: black;
  color: white;
  font-size: 14px;
  height: 200px;
  left: 20px;
  line-height: 160%;
  padding: 25px;
  position: fixed;
  top: 20px;
  width: 200px;
  z-index: 99
}

section {
  height: 600px;
  left: 40px;
  position: relative;
  top: 150px;
}

.green-glow {
  box-shadow: 0 0 150px #5A8F57; }

.red-glow {
  box-shadow: 0 0 150px #AD030A; }

.blue-glow {
  box-shadow: 0 0 150px #3E73B0; }

.purple-glow {
  box-shadow: 0 0 150px #A839A1; }

.knob-slider {
  position: relative;
  height: 500px;
  margin: 0 auto;
  width: 500px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none; }

.knob {
  border: solid 1px #ccc;
  border-radius: 50%;
  box-shadow: 0 0 2px #333;
  cursor: -moz-grab;
  cursor: -webkit-grab;
  height: 50px;
  opacity: .6;
  position: absolute;
  left: 0;
  top: 0;
  width: 50px;
  z-index: 99;
  background-color: rgba(255, 255, 255, 0);
  background-image: -webkit-gradient(radial, center center, 0, center center, 460, color-stop(0%, rgba(255, 255, 255, 0)), color-stop(100%, white), color-stop(100%, white));
  background-image: -webkit-radial-gradient(center, ellipse, rgba(255, 255, 255, 0) 0%, white 100%, white);
  background-image: radial-gradient(  ellipse at center, rgba(255, 255, 255, 0) 0%, white 100%, white);
  -webkit-transition: opacity 0.2s ease-in-out;
  -moz-transition: opacity 0.2s ease-in-out;
  transition: opacity 0.2s ease-in-out;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none; }

.knob:hover {
  box-shadow: 0 0 5px #666;
  opacity: 1; }

.knob.grab {
  cursor: -moz-grabbing;
  cursor: -webkit-grabbing; }

.instructions {
  color: white;
  font-family: 'Shadows Into Light Two', cursive;
  right: 40px;
  position: absolute;
  text-align: center;
  width: 150px;
  -webkit-transform: rotate(-45deg);
  -ms-transform: rotate(-45deg);
  -o-transform: rotate(-45deg);
  -moz-transform: rotate(-45deg);
  transform: rotate(-45deg);
}

.knob-circle {
  background: #18161e url(https://dl.dropboxusercontent.com/u/2402696/codepen-demos/radial-slider/assets/i/circle-bg.png) center no-repeat;
  border: solid 5px #000;
  border-radius: 50%;
  cursor: pointer;
  height: 100%;
  overflow: hidden;
  position: relative;
  width: 100%;
  -webkit-background-clip: padding-box;
  background-clip: padding-box;
  position: relative;
  -webkit-transition: box-shadow 1s ease-in-out;
  -moz-transition: box-shadow 1s ease-in-out;
  transition: box-shadow 1s ease-in-out;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none; }

.circle {
  border-radius: 50%;
  display: block;
  height: 500px;
  opacity: 0;
  overflow: hidden;
  position: absolute;
  width: 500px;
  -webkit-transition: -webkit-transform .3s ease-in-out;
  -moz-transition: -moz-transform .3s ease-in-out;
  transition: transform .3s ease-in-out;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none; }
  .circle img {
    border-radius: 50%; }

.footer {
  color: white;
  font-size: 8px;
  text-align: center; }
  .footer p {
    line-height: 140%; }
            
          
!
            
              var RS = RS || {};
RS.Site = (function(){
	'use strict';
	$(document).on('ready', function(){
		var RadialSlider = {
			containerObject: {},
			knobObject: {},
			knobCircle: null,
			dragging: null,
			init: function ($container, $knob, $kCircle) {
				//Define the Container Object
				this.containerObject.element = $container;
				this.containerObject.offsetTop = this.containerObject.element.offset().top;
				this.containerObject.offsetLeft = this.containerObject.element.offset().left;
				this.containerObject.height = this.containerObject.element.outerHeight()/2;
				this.containerObject.width = this.containerObject.element.outerWidth()/2;
				this.containerObject.centerX = this.containerObject.offsetLeft + this.containerObject.width;
				this.containerObject.centerY = this.containerObject.offsetTop + this.containerObject.height;

				//Define the Knob Object
				this.knobObject.element = $knob.attr('unselectable', 'on').css('transformOrigin', this.containerObject.width+'px '+ this.containerObject.height+'px');
				this.knobObject.height = this.knobObject.element.outerHeight()/2;
				this.knobObject.width = this.knobObject.element.outerWidth()/2;
				this.knobObject.posX = - this.knobObject.width;
				this.knobObject.posY = this.containerObject.height - this.knobObject.height;

				//Define Knob Circle
				this.knobCircle = $kCircle.attr('unselectable', 'on').addClass('green-glow');
				this.knobCircle.find('img').attr('draggable', 'false');

				//Actions
				this.bindUIActions();
				this.rotateKnob(45);
				this.slideCircle(0);
			},
			bindUIActions: function () {
				var _this = this;

				document.onselectstart = function () { return false; };

				$(document.body).on('mousemove', function(e) {
					var
					newPageX = -1 * (e.pageX - _this.containerObject.centerX),
					newPageY = -1 * (e.pageY - _this.containerObject.centerY);

					if (_this.dragging) {
						var
						deg = Math.floor(_this.calculatePolar(newPageX, newPageY));

						$('.instructions').fadeOut('fast');

						_this.rotateKnob(deg);
						_this.slideCircle(deg);
					}
				});

				$(document.body).on('mousedown', '.knob', function (e) {
					_this.dragging = $(e.target);
					_this.knobObject.element.addClass('grab');
				});

				$(document.body).on('mouseup', function () {
					_this.dragging = null;
					_this.knobObject.element.removeClass('grab');
				});

				_this.knobCircle.on('click', function(e) {
					var
					newPageX = -1 * (e.pageX - _this.containerObject.centerX),
					newPageY = -1 * (e.pageY - _this.containerObject.centerY),
					deg = Math.floor(_this.calculatePolar(newPageX, newPageY));

					$('.instructions').fadeOut('fast');

					_this.rotateKnob(deg);
					_this.slideCircle(deg);

					e.preventDefault();
				});
			},
			calculatePolar: function (valX, valY) {
				var
				x = valX,
				y = valY,
				theta = Math.atan(y/x)*360/2/Math.PI;

				if (x >= 0 && y >= 0) {
					theta = theta;
				} else if (x < 0 && y >= 0) {
					theta = 180 + theta;
				} else if (x < 0 && y < 0) {
					theta = 180 + theta;
				} else if (x > 0 && y < 0) {
					theta = 360 + theta;
				}

				return theta;
			},
			slideCircle: function (deg) {
				var $kCircle = this.knobCircle;

				$kCircle.children().css({
					'transform': 'translate3d(-500px,0,0)'
				});

				$kCircle.attr('class', 'knob-circle');

				if(deg >= 0 && deg < 90) {
					$kCircle.addClass('green-glow');
					$('.circle:nth-child(1)').css({
						'transform': 'translate3d(0,0,0)',
						opacity: 1
					});
					$('.circle:nth-child(2)').css({
						'transform': 'translate3d(500px,0,0)',
						opacity: 0
					});
				} else if(deg >= 90 && deg < 180) {
					$kCircle.addClass('red-glow');
					$('.circle:nth-child(2)').css({
						'transform': 'translate3d(0,0,0)',
						opacity: 1
					});
					$('.circle:nth-child(3)').css({
						'transform': 'translate3d(500px,0,0)',
						opacity: 0
					});
				} else if(deg >= 180 && deg < 270) {
					$kCircle.addClass('blue-glow');
					$('.circle:nth-child(3)').css({
						'transform': 'translate3d(0,0,0)',
						opacity: 1
					});
					$('.circle:nth-child(4)').css({
						'transform': 'translate3d(500px,0,0)',
						opacity: 0
					});
				} else if(deg >= 270 && deg < 360) {
					$kCircle.addClass('purple-glow');
					$('.circle:nth-child(4)').css({
						'transform': 'translate3d(0,0,0)',
						opacity: 1
					});
					$('.circle:nth-child(1)').css({
						'transform': 'translate3d(500px,0,0)',
						opacity: 0
					});
				}
			},
			rotateKnob: function (deg) {
				this.knobObject.element.css('transform','rotate('+deg+'deg) translate('+ this.knobObject.posX +'px, '+ this.knobObject.posY +'px)');
			}
		};

		var
		$container = $('.knob-slider'),
		$knob = $('.knob'),
		$kCircle = $('.knob-circle');

		RadialSlider.init($container, $knob, $kCircle);

	});

}());
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console