1
1
<!DOCTYPE html>
2
2
< html >
3
3
< head >
4
+ < meta name ="viewport " content ="width=device-width, initial-scale=1, minimum-scale=1 ">
4
5
< meta http-equiv ="Cache-Control " content ="no-cache, no-store, must-revalidate ">
5
6
< meta http-equiv ="Pragma " content ="no-cache ">
6
7
< meta http-equiv ="Expires " content ="0 ">
45
46
width : 7px ;
46
47
top : 50% ;
47
48
transform : translateY (-50% );
49
+ touch-action : none;
48
50
}
49
51
.color-picker-marker {
50
52
height : 7px ;
94
96
line-height : 1 ;
95
97
}
96
98
.wrap {
97
- width : 800 px ;
99
+ width : 100 % ;
98
100
margin : 0 auto;
99
101
}
102
+ @media (min-width : 800px ) {
103
+ .wrap {
104
+ width : 800px ;
105
+ }
106
+ }
100
107
.palette {
101
108
height : 20px ;
102
109
}
136
143
.sendSpan , .editSpan {
137
144
cursor : pointer;
138
145
}
146
+ h1 {
147
+ font-size : 1.6rem ;
148
+ }
139
149
</ style >
140
150
</ head >
141
151
< body >
@@ -349,24 +359,31 @@ <h1 style="display: flex; align-items: center;">
349
359
var gradientLength = maxX - minX + 1 ;
350
360
351
361
elmnt . onmousedown = dragMouseDown ;
362
+ elmnt . ontouchstart = dragMouseDown ;
352
363
353
364
function dragMouseDown ( e ) {
354
365
removeTrashcan ( event )
355
366
e = e || window . event ;
356
- e . preventDefault ( ) ;
367
+ var isTouch = e . type . startsWith ( 'touch' ) ;
368
+ if ( ! isTouch ) e . preventDefault ( ) ;
357
369
// get the mouse cursor position at startup:
358
- mousePos = e . clientX ;
370
+ mousePos = isTouch ? e . touches [ 0 ] . clientX : e . clientX ;
359
371
d . onmouseup = closeDragElement ;
372
+ d . ontouchcancel = closeDragElement ;
373
+ d . ontouchend = closeDragElement ;
360
374
// call a function whenever the cursor moves:
361
375
d . onmousemove = elementDrag ;
376
+ d . ontouchmove = elementDrag ;
362
377
}
363
378
364
379
function elementDrag ( e ) {
365
380
e = e || window . event ;
366
- e . preventDefault ( ) ;
381
+ var isTouch = e . type . startsWith ( 'touch' ) ;
382
+ if ( ! isTouch ) e . preventDefault ( ) ;
367
383
// calculate the new cursor position:
368
- posNew = mousePos - e . clientX ;
369
- mousePos = e . clientX ;
384
+ var clientX = isTouch ? e . touches [ 0 ] . clientX : e . clientX ;
385
+ posNew = mousePos - clientX ;
386
+ mousePos = clientX ;
370
387
mousePosInGradient = mousePos - ( minX + 1 )
371
388
372
389
truePos = Math . round ( ( mousePosInGradient / gradientLength ) * 256 ) ;
@@ -393,7 +410,10 @@ <h1 style="display: flex; align-items: center;">
393
410
function closeDragElement ( ) {
394
411
/* stop moving when mouse button is released:*/
395
412
d . onmouseup = null ;
413
+ d . ontouchcancel = null ;
414
+ d . ontouchend = null ;
396
415
d . onmousemove = null ;
416
+ d . ontouchmove = null ;
397
417
}
398
418
}
399
419
0 commit comments