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
| <!DOCTYPE html>
<html>
<head>
<title></title>
<style>
#stage{
margin:2% 25%;
background :#f0e5cb;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js"></script>
</head>
<body>
<svg width="50%" height="auto" viewBox="0 0 1000 600" id="stage"></svg>
<script>
function Button(x,y,w,h){
var _Text1 ="Button",_Text2="";
var bascule=false;
var form=s.rect(x,y,w,h,7).attr({
'stroke-width' :1,
stroke: '#707070'});
var str=s.text(x + w/2 ,y + h/2, _Text1).attr({
"font-family":"Tahoma",
"font-size":22,
fill:'black',
'text-anchor':"middle",
"dominant-baseline":"middle"
});
var group = s.group( form,str ).attr({ "cursor" : "pointer"});
this.innerHTML=group;
Object.defineProperties(this, {
"titre": {
get: function () {
return _Text1;
},
set: function (value) {
_Text1 = value;
str.attr({'text':value});
}
}
});
Object.defineProperties(this, {
"titreclick": {
get: function () {
return _Text2;
},
set: function (value) {
_Text2 = value;
}
}
});
var lineairev1 = s.gradient("l(0, 0, 0, 1) #cfcfcf:50-#dddddd:5-#ebebeb:20-#f2f2f2:25");
var lineairev2 = s.gradient("l(0, 0, 0, 1) #bef6fd:20-#a7d9f5:50-#d9f0f2:15-#eaf6f2:15");
var lineairev3 = s.gradient("l(0, 0, 0, 1) #98d1ef:20-#66afd7:50-#c4e5f6:15-#deedf6:15");
function skin(order){
switch(order){
case (0): form.attr({ fill:lineairev1} );
break;
case (1): form.attr({fill: lineairev2 });
break;
case (2): form.attr({fill:lineairev3});
break;
}
}
skin(0);
function handleMouseOver(e){
skin(1);
}
function handleMouseOut(e){
skin(0);
}
function handleMouseDown(e){
bascule=!bascule;
skin(2);
caption();
}
function caption(){
if (_Text2 !='' ){
if (bascule){
str.attr({'text':_Text2});
} else {
str.attr({'text':_Text1});
}
}
else {
str.attr({'text':_Text1});
}
}
group.mouseout(handleMouseOut);
group.mouseover(handleMouseOver);
group.mousedown(handleMouseDown);
group.mouseup(handleMouseOut);
}
var s = Snap("#stage");
var mybutton=new Button(20,20,150,50);
mybutton.titre='Start';
mybutton.titreclick='Stop';
mybutton.innerHTML.click(function(e){
console.log("ça marche");
});
</script>
</body>
</html> |