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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
| <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style>
#conteneur * { /*---- petite erreur, ici ne pas mettre de sélecteur direct, ( #conteneur>* ) --------------*/
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
}
.slide {
position:relative;
overflow:hidden; /* la valeur "none" n'existe pas cet attribut */
margin-top: 5px;
border: 1px solid rgb(240, 240, 240);
}
.slide>div {
position:absolute;
border: 1px solid rgb(230, 230, 230);
}
#fond5, #fond6 {
border: 1px solid rgb(240, 240, 240);
border-radius: 10px;
background: linear-gradient(to bottom, rgba(220, 220, 220, 0) 44%, rgba(33, 180, 226, 1) 53%, rgba(220, 220, 220, 0) 63%);
margin-top: 5px;
}
#fond5>div , #fond6>div {
background: linear-gradient(to bottom, rgba(220, 227, 145, 0.1) 0%, rgba(97, 196, 25, 1) 50%, rgba(180, 227, 145, 1) 100%);
}
#fond5.ModActif, #fond6.ModActif {
border: 1px solid rgb(250, 250, 250);
border-radius: 10px;
background: linear-gradient(to bottom, rgba(255, 255, 255, 1) 44%, rgba(255, 0, 255, 1) 53%, rgba(255, 255, 255, 1) 63%);
box-shadow: 0 0 1em #BDBDBD inset;
margin-top: 5px;
}
#fond5.ModActif>div, #fond6.ModActif>div {
background: linear-gradient(to bottom, rgba(240, 240, 0, 1) 0%, rgba(255, 50, 0, 1) 50%, rgba(240, 240, 0, 1) 100%);
}
#fond7 {
border: 1px solid rgb(245, 245, 245);
border-radius: 10px;
background: linear-gradient(to bottom, rgba(255, 255, 255, 0.1) 44%, rgba(0, 255, 0, 1) 53%, rgba(255, 255, 255, 1) 63%);
margin-top: 5px;
}
#fond7>div {
box-shadow: 0 0 1em #58D3F7 inset;
background-color: rgb(245, 245, 245);
}
#fond7.ModActif {
border: 1px solid rgb(250, 250, 250);
border-radius: 10px;
background: linear-gradient(to bottom, rgba(255, 255, 255, 1) 44%, rgba(255, 0, 0, 1) 53%, rgba(255, 255, 255, 1) 63%);
box-shadow: 0 0 1em #BDBDBD inset;
margin-top: 5px;
}
#fond7.ModActif>div {
box-shadow: 0 0 1em #6E6E6E inset;
background-color: rgb(245, 245, 245);
}
</style>
<script type="text/javascript">
var LrG;
var Crs;
var oX;
var newX;
var Mx;
var Dv;
var dragg;
function Start(event) {
console.log(event.target.id);
Crs = event.target;
dragg = Crs.parentElement;
// dragg.className = dragg.getAttribute("cl2");
addClass(dragg, "ModActif");
LrG = Crs.parentElement.offsetWidth - (Crs.offsetWidth / 2);
Dv = (LrG - (Crs.offsetWidth / 2)) / 100;
oX = event.clientX + (document.documentElement.scrollLeft + document.body.scrollLeft);
Mx = oX - Crs.offsetLeft;
dragg.addEventListener("mousemove", dragging, false);
dragg.addEventListener("mouseup", relache, false);
dragg.addEventListener("mouseleave", relache, false);
}
function dragging(event) {
newX = event.clientX + (document.documentElement.scrollLeft + document.body.scrollLeft);
console.log("deplacement " + newX);
var posX = newX - Mx;
if (posX < 0) {
posX = 0;
}
if (posX > LrG - (Crs.offsetWidth / 2)) {
posX = LrG - (Crs.offsetWidth / 2);
}
Crs.style.position = "absolute";
Crs.style.left = posX + "px";
document.getElementById("res").innerHTML = Crs.id + " : " + Math.round(Crs.offsetLeft / Dv);
}
function relache(event) {
console.log(Crs.id);
dragg.removeEventListener("mousemove", dragging);
dragg.removeEventListener("mouseup", relache);
dragg.removeEventListener("mouseleave", relache);
//dragg.className = dragg.getAttribute("cl1");
removeClass(dragg, "ModActif");
}
function ajoute() {
var messlides = document.getElementsByClassName("slide");
console.log("attribution de l'evenement down");
for (var i = 0; i < messlides.length; i++) {
messlides[i].getElementsByTagName("DIV")[0].addEventListener("mousedown", Start, false);
console.log("slider : " + messlides[i].id);
console.log("curseur : " + messlides[i].getElementsByTagName("DIV")[0].id);
}
}
/* fonctions de substitution sur l'ajout / suppression de Classe pour les anciennes versin de JS */
function hasClass(el, className) {
return !!el.className.match(new RegExp('(\\s|^)' + className + '(\\s|$)'));
}
function addClass(el, className) {
if (!hasClass(el, className))
el.className += " " + className;
}
function removeClass(el, className) {
if (hasClass(el, className)) {
var reg = new RegExp('(\\s|^)' + className + '(\\s|$)');
el.className = el.className.replace(reg, ' ');
}
}
/* */
</script>
</head>
<body>
<div id="conteneur1" style="position:absolute;height:200px;left:28px;width:350px;border:2 solid red;">
des slides pas comme les autres
<p id="res">position</p>
<br/>
<br/>
<div id="fond5" class="slide" style="width:300px;height:26px;">
<div id="Crs5" class="cur" style="top:1px;width:26px;height:26px;border-radius:8px;" unselectable="on"></div>
</div>
<div id="fond6" class="slide" style="width:300px;height:26px;">
<div id="Crs6" class="cur" style="top:1px;width:26px;height:26px;border-radius:8px;" unselectable="on"></div>
</div>
<div id="fond7" class="slide" style="width:300px;height:26px;">
<div id="Crs7" class="cur" style="top:1px;width:26px;height:26px;border-radius:50%;" unselectable="on"></div>
</div>
</div>
<script>
ajoute();
</script>
</body>
</html> |
Partager