css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

            
              <html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="styles.css">
</head>

<body>
    <div class="dial">
        <ul class="inner">
            <li class='dial-option'>
                <p>0</p>
            </li>
            <li class='dial-option'>
                <p>1</p>
            </li>
            <li class='dial-option'>
                <p>2</p>
            </li>
            <li class='dial-option'>
                <p>3</p>
            </li>
            <li class='dial-option'>
                <p>4</p>
            </li>
            <li class='dial-option'>
                <p>5</p>
            </li>
            <li class='dial-option'>
                <p>6</p>
            </li>
            <li class='dial-option'>
                <p>7</p>
            </li>
            <li class='dial-option'>
                <p>8</p>
            </li>
            <li class='dial-option'>
                <p>9</p>
            </li>
            <li class='dial-option'>
                <p>*</p>
            </li>
            <li class='dial-option'>
                <p>+</p>
            </li>
            <li class='dial-option'>
                <p>-</p>
            </li>
            <li class='dial-option'>
                <p>/</p>
            </li>
            <li class='dial-option'>
                <p>%</p>
            </li>
            <li class='dial-option'>
                <p>=</p>
            </li>
        </ul>
    </div>
    <div class="instructions">
        <p>Drag mouse to move the dial. Not suited for small screens.</p>
        <p>Every time you switch directions, you select the option that you were on win you switched.</p>
        <p>In order to clear the calculator, spin left until the operation text (Top Left) says 'CLEAR'</p>
      <p>To clear the calculator after an equation, simply select the equal sign instead of another mathmetical sign. (Do this when the numbers are disabled)</p>
    </div>
    <span class="operation">0 + 0</span>
    <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
        crossorigin="anonymous"></script>
</body>

</html>
            
          
!
            
              html {
    height: 100%;
    /* margin: 0; */
}

body {
    height: 100%;
    margin: 0;
}

.dial {
    width: 100%;
    height: 100%;
    background-color: #545454;
    overflow: hidden;
    display: flex;
    justify-content: center;
    position: relative;
}

.dial .overlay {
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(270deg, #545454 8.11%, rgba(84, 84, 84, 0) 48.41%, #545454 93.52%);
    top: 0;
    left: 0;
}

.dial-option {
    text-align: center;
    background-color: #a7a7a7;
    z-index: 1;
    user-select: none;
    flex-shrink: 0;
    transition: transform 150ms cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.dial-option.disabled {
    opacity: .5;
}

.dial-option.selected {
    z-index: 2;
    transform: translate(0em) !important;
}

.dial-option.adjacent {
    margin-bottom: 30px;
}

.inner {
    width: 20em;
    height: 20em;
    border-radius: 50%;
    padding: 0;
    list-style: none;
    margin: 5em auto 0;
}

.inner>* {
    display: block;
    position: absolute;
    top: 50%;
    left: 50%;
    border-radius: 50%;
    background-color: aliceblue;
    margin: -3em;
    width: 42px;
    padding: 10px;
    height: 42px;
}

.operation {
    position: absolute;
    top: 5px;
    left: 5px;
    padding: 5px;
    background-color: whitesmoke;
    color: rgb(31, 31, 31);
}

.instructions {
    position: absolute;
    top: 40px;
    left: 5px;
    padding: 5px;
    background-color: whitesmoke;
    color: rgb(31, 31, 31);
    max-width: 500px;
}
            
          
!
            
              mouse_anchor = 0;
mouse_difference = 0;
current_mouse_x = 0;
mousedown = false;


dials = [];
sign = '';
numberOne = '';
numberTwo = '';

function Dial(element) {
    this.order = []; /* Current order of dial */
    this.order_backup = [];
    this.order_string = "";
    this.dial_rotations = [];
    this.dialoptions = [];
    this.movement_streak = 0;
    this.mouseover = false;
    this.loop = true; /* Will the dial loop around so that it never stops spinning */
    this.movement_buffer = 70; /* Delay between mouse movement and order changes in pixels. */
    this.movement_anim = 0;
    this.element = element;
    this.selected = 13;
    this.firstmove = true;
    this.awaiting_next_sign = false;
    this.marign = [0, 0]; /* Holds margin information for margin left (index: 0) and margin right (index: 1) */
    dials.push(this);
    return this;
}


Dial.prototype.init = function () {
    this.dialoptions = $(this.element).find('.dial-option');
    this.angle = 360 / this.dialoptions.length;
    for (var i = 0; i < this.dialoptions.length; i++) {
        $(this.dialoptions[i])
            .toggleClass('option-' + i)
            .css('transform', 'rotate(' + ((this.angle * i) + 11205) + 'deg) translate(10em) rotate(-' + ((this.angle * i) + 11205) + 'deg)');
        this.order.push(i);
        this.dial_rotations[i] = ((this.angle * i) + 11205);
        $('.dial-option.option-' + this.selected).toggleClass('selected');
    }
}

Dial.prototype.step = function () {
    if (this.mouseover && mousedown) {
        this.movement_anim = mouse_difference * .0001;
        if (mouse_difference > this.movement_buffer) {
            this.rotateDial(this.angle);
            this.movement_actions(1);
            mouse_anchor = current_mouse_x;
        } else if (mouse_difference < -this.movement_buffer) {
            this.rotateDial(-this.angle);
            this.movement_actions(-1);
            mouse_anchor = current_mouse_x;
        }
    }
}

Dial.prototype.movement_actions = function (dir) {
    // First Movement or Change in direction
    if (Math.sign(this.movement_streak) != dir) {
        this.movement_streak = dir;

        if (!this.firstmove && !($('.dial-option.option-' + this.selected).hasClass('disabled'))) {
            this.processInput();
        }

        this.firstmove = false;
    } else {
        this.movement_streak += dir;
        if (this.movement_streak < -(this.order.length * 1.5) - 2) {
            numberOne = '';
            numberTwo = '';
            sign = '';
            $('.operation').html('CLEAN');
            this.movement_streak = 0;
            firstmove = true;
        }
    }

    $('.selected').toggleClass('selected');
    this.selected += -dir;

    if (this.selected == -1) {
        this.selected = this.order.length - 1;
    }
    if (this.selected == this.order.length) {
        this.selected = 0;
    }
    $('.dial-option.option-' + this.selected).toggleClass('selected');
}

Dial.prototype.disableNumbers = function () {
    for (var i = 0; i <= 9; i++) {
        $('.dial-option.option-' + i).toggleClass('disabled');
    }
    console.log('sFSD');
    this.awaiting_next_sign = true;
}

Dial.prototype.disableSigns = function () {
    for (var i = 10; i <= 15; i++) {
        $('.dial-option.option-' + i).toggleClass('disabled');
    }
}

Dial.prototype.enableAll = function () {
    this.awaiting_next_sign = false;
    $('.disabled').toggleClass('disabled');
}

Dial.prototype.processInput = function () {
    data = $('.selected').text().replace(/ /g, '');
    num = '';
    queued_sign = '';
    switch (this.selected) {
        case 0:
            num += '0';
            break;
        case 1:
            num += '1';
            break;
        case 2:
            num += '2';
            break;
        case 3:
            num += '3';
            break;
        case 4:
            num += '4';
            break;
        case 5:
            num += '5';
            break;
        case 6:
            num += '6';
            break;
        case 7:
            num += '7';
            break;
        case 8:
            num += '8';
            break;
        case 9:
            num += '9';
            break;
        case 10:
            sign = '*';
            break;
        case 11:
            sign = '+';
            break;
        case 12:
            sign = '-';
            break;
        case 13:
            sign = '/';
            break;
        case 14:
            sign = '%';
            break;
        case 15:
            if (this.awaiting_next_sign) {
                this.enableAll();
                numberOne = '';
            } else {
                console.log('here');
                equate();
            }
            break;
    }

    if (numberOne == '' && !this.awaiting_next_sign) {
        this.enableAll();
    }

    if (this.awaiting_next_sign && sign != '') {
        this.enableAll();
    }

    // this.awaiting_next_sign = false;
    if (sign == '') {
        numberOne += num;
    } else {
        numberTwo += num;
    }
    $('.operation').html(numberOne + ' ' + sign + ' ' + numberTwo);
}

Dial.prototype.rotateDial = function (rotateBy) {
    // console.log(this.dialoptions);
    for (var i = 0; i < this.dialoptions.length; i++) {
        if (!rotateBy) {
            rotateBy = this.dial_rotations[i] + this.movement_anim;
            $(this.dialoptions[i]).css('transform', 'rotate(' + (rotateBy) + 'deg) translate(10em) rotate(-' + (rotateBy) + 'deg)');
        } else {
            this.dial_rotations[i] += rotateBy;
            $(this.dialoptions[i]).css('transform', 'rotate(' + (this.dial_rotations[i]) + 'deg) translate(10em) rotate(-' + (this.dial_rotations[i]) + 'deg)');
        }
    }
}

function equate() {
    if (sign != '' && numberOne != '' && numberTwo != '') {
        switch (sign) {
            case '*':
                numberOne = parseInt(numberOne) * parseInt(numberTwo);
                break;
            case '/':
                numberOne = parseInt(numberOne) / parseInt(numberTwo);
                break;
            case '+':
                numberOne = parseInt(numberOne) + parseInt(numberTwo);
                break;
            case '-':
                numberOne = parseInt(numberOne) - parseInt(numberTwo);
                break;
            case '%':
                numberOne = parseInt(numberOne) % parseInt(numberTwo);
                break;
        }
        dial.disableNumbers();
        numberTwo = '';
        sign = '';
        return true;
    }
    return false;
}



function elementToDial(element, callback) {
    for (var i = 0; i < dials.length; i++) {
        if (element = dials[0].element) {
            callback(dials[0]);
            return dials[0];
        }
    }
}

function step() {
    for (var i = 0; i < dials.length; i++) {
        dials[i].step();
    }
}


window.addEventListener('mousedown', function (e) {
    mousedown = true;
    mouse_anchor = e.pageX;
});

window.addEventListener('mouseup', function (e) {
    mousedown = false;
    mouse_difference = 0;
});

window.addEventListener('mousemove', function (e) {
    if (mousedown) {
        current_mouse_x = e.pageX
        mouse_difference = current_mouse_x - mouse_anchor;
        step();
    }
});


$('.dial')
    .mouseenter(function () {
        elementToDial(this, function (dial) {
            dial.mouseover = true;
            mouse_anchor = current_mouse_x;
            // console.log("mouseover is " + dial.mouseover);
        });
    })
    .mouseleave(function () {
        elementToDial(this, function (dial) {
            dial.mouseover = false;
            mouse_anchor = current_mouse_x;
            // console.log("mouseover is " + dial.mouseover);
        });
    });


dial = new Dial($('.dial'));
dial.init();
dial.disableSigns();
            
          
!
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.
Loading ..................

Console