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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
| <!DOCTYPE html>
<html>
<head>
<meta name="viewport"
content="width=device-width,
initial-scale=1.0,
user-scalable=no" /> <!-- zoom interdit -->
<title>Commande</title>
<style>
#container {
width: 100%;
height:400px;
background-color: #133;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
border-radius: 7px;
touch-action: none;
}
#item {
width: 150px;
height: 100px;
background-color: rgb(245, 230, 99);
border: 10px solid rgba(136, 16, 136, .5);
border-radius: 40%;
touch-action: none;
user-select: none;
}
#item:active {
background-color: rgba(168, 218, 220, 1.00);
}
#item:hover {
cursor: pointer;
border-width: 20px;
}
#container2 {
width: 100%;
height:20px;
background-color: #333;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
touch-action: none;
}
#item2 {
width: 20px;
height: 20px;
background-color: rgb(45, 230, 99);
border: 5px solid rgba(6, 6, 6, .5);
touch-action: none;
user-select: none;
}
#item2:active {
background-color: rgba(168, 28, 220, 1.00);
}
#item2:hover {
cursor: pointer;
border-width: 12px;
}
</style>
</head>
<body>
<div id="outerContainer">
<div id="container">
<div id="item">
</div>
</div>
<div class="slidecontainer">
<p><center>Trim direction</center></p>
<div id="container2">
<div id="item2">
</div>
//<div id="affichage"></div>
<script language="text/javascript">document.getElementById('affichage').innerHTML = currentX;</script>
</div>
<script>
var dragItem = document.querySelector("#item");
var container = document.querySelector("#container");
var dragItem2 = document.querySelector("#item2");
var container2 = document.querySelector("#container2");
var active = false;
var active2 = false;
var currentX=0;
var currentX2 = 0;
var currentY = 0;
var currentY2 = 0;
var initialX = 0;
var initialX2 = 0;
var initialY = 0;
var initialY2 = 0;
var xOffset = 0;
var yOffset = 0;
var xOffset2 = 0;
var yOffset2 = 0;
container.addEventListener("touchstart", dragStart, false);
container.addEventListener("touchend", dragEnd, false);
container.addEventListener("touchmove", drag, false);
container.addEventListener("mousedown", dragStart, false);
container.addEventListener("mouseup", dragEnd, false);
container.addEventListener("mousemove", drag, false);
container2.addEventListener("touchstart", dragStart2, false);
container2.addEventListener("touchend", dragEnd2, false);
container2.addEventListener("touchmove", drag2, false);
container2.addEventListener("mousedown", dragStart2, false);
container2.addEventListener("mouseup", dragEnd2, false);
container2.addEventListener("mousemove", drag2, false);
function dragStart(e) {
if (e.type === "touchstart") {
initialX = e.touches[0].clientX - xOffset;
initialY = e.touches[0].clientY - yOffset;
} else {
initialX = e.clientX - xOffset;
initialY = e.clientY - yOffset;
}
if (e.target === dragItem) {
active = true;
active2 = false;
}
}
function drag(e) {
if (active) {
e.preventDefault();
if (e.type === "touchmove") {
currentX = e.touches[0].clientX - initialX ;
currentY = e.touches[0].clientY - initialY;
} else {
currentX = e.clientX - initialX;
currentY = e.clientY - initialY;
}
xOffset = currentX2;
yOffset = currentY;
setTranslate(currentX, currentY, dragItem);
}
}
function dragEnd(e) {
setTranslate(currentX2, currentY, dragItem);
initialX = currentX ;
initialY = currentY;
active = false;
}
function dragStart2(e) {
if (e.type === "touchstart") {
initialX2 = e.touches[0].clientX - xOffset2;
initialY2=0;
} else {
initialX2 = e.clientX - xOffset2;
initialY2=0;
//initialY2 = e.clientY - yOffset2;
}
if (e.target === dragItem2) {
active2 = true;
}
initialX = initialX2 ;
}
function drag2(e) {
if (active2) {
e.preventDefault();
if (e.type === "touchmove") {
currentX2 = e.touches[0].clientX - initialX2;
currentY2 = e.touches[0].clientY - initialY2;
} else {
currentX2 = e.clientX - initialX2;
currentY2 = e.clientY - initialY2;
}
xOffset2 = currentX2;
xOffset = currentX2;
yOffset2 = currentY2;
setTranslate(currentX2, 0, dragItem2);
setTranslate(currentX2, currentY, dragItem);
}
}
function dragEnd2(e) {
initialX2 = currentX2;
initialY2 = currentY2;
setTranslate(currentX2, 0, dragItem2);
currentX = currentX2;
setTranslate(currentX, currentY, dragItem);
currentY2+"<center>";
active2 = false;
}
function setTranslate(xPos, yPos, el) {
el.style.transform = "translate3d(" + xPos + "px, " + yPos + "px, 0)";
}
</script>
</body>
</html> |
Partager