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

              
                <main>
  <h1>Input spinner<small>for iOS Safari</small></h1>
  <form action="">
    <div class="spinnerField">
       <input type="number" min="0" step="5" name="count" id="count" placeholder="0">
      <button type="button" id="plus"  class="plus"></button>
      <button type="button" id="minas"  class="minas"></button>
      <span class="error">Enter a multiple of</span>
    </div>
    <button class="button-submit" type="submit">submit (validation check)</button>
  </form>
  <div class="console">
    <h2>option</h2>
    <dl>
      <dt>step</dt>
      <dd><input type="number" inputmode="decimal" id="stepOption" min="1" step="1" value="5" /></dd>
    </dl>
  </div>
</main>
              
            
!

CSS

              
                @import url('//fonts.googleapis.com/css?family=Roboto:100,400,700');
html, * {
  font-family: 'Roboto';
  box-sizing: border-box;
}

html {
  // disable to double tap zoom
  touch-action: manipulation;
}

main {
  max-width: calc(100% - 4rem);
  width: 38ch;
  margin: 0 auto;
  padding: 0 0 2rem;
}

h1 {
  margin: 1em 0;
  font-size: 3rem;
  line-height: 1.5;
  small {
    font-size: 2rem;
    display: block;
  }
}

form {
  margin: 1rem 0;
}

.spinnerField {
  position: relative;
  height: 3em;
  width: 100%;

  input[type="number"] {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    max-width: 100%;
    display: block;
    font-size: 1.5rem;
    padding: 0.5em 3rem;
    text-align: right;
    appearance: none;
    border: 2px solid lightgray;
    border-radius: 0.2em;
    
    // default spinner button
    &::-webkit-inner-spin-button {
      appearance: none;
    }
  }
  
  .error {
    position: absolute;
    bottom: calc(100% + 1rem);
    right: 0;
    display: inline-flex;
    padding: 0.4rem 1rem;
    font-size: 1rem;
    line-height: (23/16);
    color: white;
    white-space: nowrap;
    pointer-events: none;
    background-color: red;
    border-radius: 99em;
    opacity: 0;
    transition: transform 200ms, opacity 200ms;
    transform: translateY(1rem);

    &::after {
      width: 0;
      height: 0;
      position: absolute;
      top: 100%;
      right: 0;
      left: 0;
      display: block;
      margin: 0 auto;
      content: '';
      border-top: 1rem solid red;
      border-right: 0.5rem solid transparent;
      border-left: 0.5rem solid transparent;
    }
  }
  
  input[type="number"]:invalid ~ .error {
    pointer-events: default;
    opacity: 1;
    transform: translateY(0);
  }
  
  button {
    width: 3rem;
    height: 3rem;
    position: absolute;
    appearance: none;
    top: 0;
    bottom: 0;
    padding: 0;
    margin: auto 0;
    display: block;
    border: none;
    background-color: transparent;
    
    &::before,
    &::after {
      content: '';
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      margin: auto;
      background-color: currentColor;
      display: block;
    }
    
    &::before {
      width: 12px;
      height: 2px;
    }
    &::after {
      height: 12px;
      width: 2px;
    }
    
    
    &.plus {
      right: 0;
    }
    &.minas {
      left: 0;
      &::after {
        content: none;
      }
    }
  }
}

.button-submit {
  appearance: none;
  margin: 1rem 0;
  width: 100%;
  background-color: black;
  color: white;
  padding: 1rem;
  font-size: 1rem;
  border: none;
  border-radius: 0.25rem;
}

.console {
  margin-top: 2rem;
  position: relative;
  h2 {
    font-weight: bold;
    
  }
  dl {
    margin-top: 1rem;
    display: flex;
    dt,dd {
      display: flex;
      align-items: center;
      font-size: 1rem;
      margin-top: 0.5em;
    }
    dt {
      &::after {
        content: ':';
        margin: 0 0.25em;
      }
    }
    dd {
      input {
        font-size: 1rem;
        appearance: none;
        border-width: 0 0 1px 0;
        text-align: center;
        width: 4em;
        padding: 0.25em 0.5em;
        border-radius: 0;
        
        // default spinner button
        &::-webkit-inner-spin-button {
          appearance: none;
        }
      }
    }
  }
}
              
            
!

JS

              
                // Interface
interface hasCurrentTargetEvent {
  currentTarget: HTMLUnknownElement;
};

interface SpinnerClass {
  private readonly input: HTMLInputElement,
  private plus: HTMLButtonElement,
  private minas: HTMLButtonElement,
};

// Spinner
class Spinner implements SpinnerClass {
  
  constructor(private readonly i:HTMLInputElement, private p:HTMLButtonElement, private m: HTMLButtonElement) {
    this.input = i;
    this.plus = p;
    this.plus.add = true;
    this.plus.addEventListener('click', this.actSpinner.bind(this), false);
    this.minas = m;
    this.minas.add = false;
    this.minas.addEventListener('click', this.actSpinner.bind(this), false);
  }
  
  get spinnerStep() {
    return this.input.getAttribute('step');
  };
  
  set spinnerStep(step: Number) {
    this.input.setAttribute('step', step);
  };
  
  actSpinner<T extends Spinner,U extends hasCurrentTargetEvent>(this: T, e: U) {
    const button = e.currentTarget;
    const add = button.add;
    const spq = +this.input.getAttribute('step');
   
    // count
    let count = +this.input.value;
    const invalid = this.input.validity.stepMismatch;
    if (invalid) count -= count % spq;
    count += spq * (add ? 1 : -1);

    // set value
    this.input.value = +count;

    // check Error
    console.log(spq);
    this.input.setCustomValidity(!invalid ? '' : `Enter a multiple of ${spq}`);
  }
}

// Instance
const myInpput = document.getElementById('count');
const myPlusButton =  document.getElementById('plus');
const myMinasButton =  document.getElementById('minas');

const mySpinner = new Spinner(myInpput, myPlusButton, myMinasButton);

// customize to step
const stepOption = document.getElementById('stepOption');

stepOption.addEventListener('change', (e) => {
  mySpinner.spinnerStep = +e.currentTarget.value;
  console.log(`now step is ${mySpinner.spinnerStep}`);
}, false);

              
            
!
999px

Console