A lightweight, dependency-free ES6 color picker you can attach to any input.
Demo: Click any input below to open the picker.
1. Include color-picker.js on your page:
<script src="https://colorpicker.likethat.studio/color-picker.min.js"></script>
2. Add the lt-colorpicker class (or any class/selector you choose) to your inputs:
<input class="lt-colorpicker" value="#FF8800">
3. Call attachColorPicker() in your own script:
document.querySelectorAll('.lt-colorpicker').forEach(input => {
attachColorPicker(input, {
direction: 'top', // 'top' | 'bottom' | 'left' | 'right'
onChange: c => console.log('Color changed to', c)
});
});
You can pass these options to attachColorPicker(input, options):
string) – where to position the popup relative to the input:
'top' (default), 'bottom', 'left', or 'right'.
function) – callback invoked with the new hex color string whenever
it
changes.