| 1 |
<!doctype html> |
| 2 |
<html lang="en"> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1"> |
| 6 |
<title>jQuery UI Slider - Colorpicker</title> |
| 7 |
<link rel="stylesheet" href="../../themes/base/all.css"> |
| 8 |
<link rel="stylesheet" href="../demos.css"> |
| 9 |
<style> |
| 10 |
#red, #green, #blue { |
| 11 |
float: left; |
| 12 |
clear: left; |
| 13 |
width: 300px; |
| 14 |
margin: 15px; |
| 15 |
} |
| 16 |
#swatch { |
| 17 |
width: 120px; |
| 18 |
height: 100px; |
| 19 |
margin-top: 18px; |
| 20 |
margin-left: 350px; |
| 21 |
background-image: none; |
| 22 |
} |
| 23 |
#red .ui-slider-range { background: #ef2929; } |
| 24 |
#red .ui-slider-handle { border-color: #ef2929; } |
| 25 |
#green .ui-slider-range { background: #8ae234; } |
| 26 |
#green .ui-slider-handle { border-color: #8ae234; } |
| 27 |
#blue .ui-slider-range { background: #729fcf; } |
| 28 |
#blue .ui-slider-handle { border-color: #729fcf; } |
| 29 |
</style> |
| 30 |
<script src="../../external/requirejs/require.js"></script> |
| 31 |
<script src="../bootstrap.js"> |
| 32 |
function hexFromRGB(r, g, b) { |
| 33 |
var hex = [ |
| 34 |
r.toString( 16 ), |
| 35 |
g.toString( 16 ), |
| 36 |
b.toString( 16 ) |
| 37 |
]; |
| 38 |
$.each( hex, function( nr, val ) { |
| 39 |
if ( val.length === 1 ) { |
| 40 |
hex[ nr ] = "0" + val; |
| 41 |
} |
| 42 |
}); |
| 43 |
return hex.join( "" ).toUpperCase(); |
| 44 |
} |
| 45 |
function refreshSwatch() { |
| 46 |
var red = $( "#red" ).slider( "value" ), |
| 47 |
green = $( "#green" ).slider( "value" ), |
| 48 |
blue = $( "#blue" ).slider( "value" ), |
| 49 |
hex = hexFromRGB( red, green, blue ); |
| 50 |
$( "#swatch" ).css( "background-color", "#" + hex ); |
| 51 |
} |
| 52 |
|
| 53 |
$( "#red, #green, #blue" ).slider({ |
| 54 |
orientation: "horizontal", |
| 55 |
range: "min", |
| 56 |
max: 255, |
| 57 |
value: 127, |
| 58 |
slide: refreshSwatch, |
| 59 |
change: refreshSwatch |
| 60 |
}); |
| 61 |
$( "#red" ).slider( "value", 255 ); |
| 62 |
$( "#green" ).slider( "value", 140 ); |
| 63 |
$( "#blue" ).slider( "value", 60 ); |
| 64 |
</script> |
| 65 |
</head> |
| 66 |
<body class="ui-widget-content" style="border:0;"> |
| 67 |
|
| 68 |
<p class="ui-state-default ui-corner-all ui-helper-clearfix" style="padding:4px;"> |
| 69 |
<span class="ui-icon ui-icon-pencil" style="float:left; margin:-2px 5px 0 0;"></span> |
| 70 |
Simple Colorpicker |
| 71 |
</p> |
| 72 |
|
| 73 |
<div id="red"></div> |
| 74 |
<div id="green"></div> |
| 75 |
<div id="blue"></div> |
| 76 |
|
| 77 |
<div id="swatch" class="ui-widget-content ui-corner-all"></div> |
| 78 |
|
| 79 |
<div class="demo-description"> |
| 80 |
<p>Combine three sliders to create a simple RGB colorpicker.</p> |
| 81 |
</div> |
| 82 |
</body> |
| 83 |
</html> |