1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
| <!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>sliderCheckBox</title>
<style>
html, body { background: #B4B7C0; }
h3 { color: #818799; text-shadow: 0 -1px 1px #555966, 0 1px 1px #d5d9e5; }
form { width: 100%; text-align: center; }
.jquery-checkbox {
font-family: "Lucida Grande", Verdana, Arial, sans-serif;
display: -moz-inline-stack;
display: inline-block;
position: relative; width: 125px;
font-size: 12px; height: 2em; line-height: 2em;
border: 1px solid #FFF;
border-color: rgba(0,0,0,.2) rgba(127,127,127, .2) rgba(255,255,255,.2);
border-radius: 3px;
-o-border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
}
.jquery-checkbox .jquery-checkbox-ruler {
display: block; width: 100%; height: 100%;
position: relative;
background: #00c900;
background-image: -webkit-gradient(linear,left top,left bottom,from(#00A900), to(#66c900));
background-image: -moz-linear-gradient(left top,left bottom,from(#00A900),to(#00c900));
border-radius: 3px;
-o-border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
}
.jquery-checkbox .jquery-checkbox-ruler .jquery-checkbox-ruler {
position: absolute; right: 0;
background: #c90000;
background-image: -webkit-gradient(linear,left top,left bottom,from(#A90000), to(#c90000));
background-image: -moz-linear-gradient(left top,left bottom,from(#A90000),to(#c90000));
transition: width .2s;
-o-transition: width .2s;
-moz-transition: width .2s;
-webkit-transition: width .2s;
}
.jquery-checkbox .jquery-checkbox-handle {
display: -moz-inline-stack; display: inline-block; position: absolute; left: 0; top: -1px; height: 100%;
}
.jquery-checkbox .jquery-checkbox-handle span {
display: -moz-inline-stack; display: inline-block; position: relative;
cursor: pointer;
padding: 0 .5em 1px;
color: #000;
text-shadow: 0 1px 0 #FFF;
background: #F5F5F5;
background-image: -webkit-gradient(linear,left top,left bottom,from(rgba(255, 255, 255, .9)),color-stop(0.5, rgba(234, 234, 234, .9)),color-stop(0.5, rgba(226, 226, 226, .9)),to(rgba(242, 242, 242, .9)));
background-image: -moz-linear-gradient(left top,left bottom,from(rgba(255, 255, 255, .9)),color-stop(0.5, rgba(234, 234, 234, .9)),color-stop(0.5, rgba(226, 226, 226, .9)),to(rgba(242, 242, 242, .9)));
border-radius: 3px;
-o-border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
transition: left .2s;
-o-transition: left .2s;
-moz-transition: left .2s;
-webkit-transition: left .2s;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.7);
}
.jquery-checkbox.checked .jquery-checkbox-ruler .jquery-checkbox-ruler {
width: 0;
}
.jquery-checkbox.checked .jquery-checkbox-handle span {
left: -100%;
}
/* !Fixes */
.lt-ie7 .jquery-checkbox .jquery-checkbox-handle .jquery-checkbox-ruler {
right: -1px;
}
</style>
<script charset="utf-8" src="../lib/jqueryui/js/jquery-1.4.2.min.js"></script>
<script>
(function($){
$.sliderCheckBox = function(options){
var opts = $.extend(true, {}, $.sliderCheckBox.defaults, options);
$("input[type='checkbox']").each(function(i, item){
if(opts.hide){
$(item).hide();
}
$("<span/>",{
html:'<span class="jquery-checkbox-ruler"><span class="jquery-checkbox-ruler"><span class="jquery-checkbox-handle"><span>' + ($(item).attr('checked') ? opts.state.checked : opts.state.unchecked) + '</span></span></span></span>',
click:function(){
var obj = $(this).data("box").obj;
var boolChecked = !obj.attr('checked');
obj.attr('checked', boolChecked);
$(".jquery-checkbox-handle > span", this).text(boolChecked ? opts.state.checked : opts.state.unchecked);
$(this).toggleClass(opts.checked, boolChecked);
}
}).data("box", {
obj: $(item)
}).addClass("jquery-checkbox").insertAfter(item);
});
};
$.sliderCheckBox.defaults = {
hide: true,
checked: "checked",
state: {
checked: 'Ouvrir',
unchecked: 'Fermer'
}
};
})(jQuery);
$(function(){
$.sliderCheckBox();
});
</script>
</head>
<body>
<form>
<h3>Inline</h3>
<p>
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
</p>
<h3>Block</h3>
<p>
<input type="checkbox" />
</p>
<p>
<input type="checkbox" />
</p>
<p>
<input type="checkbox" />
</p>
<p>
<input type="checkbox" />
</p>
</form>
</body>
</html> |
Partager