11<!DOCTYPE html>
22< html >
33 < head >
4+ < meta name ="viewport " content ="width=device-width, initial-scale=1, minimum-scale=1 ">
45 < meta http-equiv ="Cache-Control " content ="no-cache, no-store, must-revalidate ">
56 < meta http-equiv ="Pragma " content ="no-cache ">
67 < meta http-equiv ="Expires " content ="0 ">
4546 width : 7px ;
4647 top : 50% ;
4748 transform : translateY (-50% );
49+ touch-action : none;
4850 }
4951 .color-picker-marker {
5052 height : 7px ;
9496 line-height : 1 ;
9597 }
9698 .wrap {
97- width : 800 px ;
99+ width : 100 % ;
98100 margin : 0 auto;
99101 }
102+ @media (min-width : 800px ) {
103+ .wrap {
104+ width : 800px ;
105+ }
106+ }
100107 .palette {
101108 height : 20px ;
102109 }
136143 .sendSpan , .editSpan {
137144 cursor : pointer;
138145 }
146+ h1 {
147+ font-size : 1.6rem ;
148+ }
139149 </ style >
140150 </ head >
141151< body >
@@ -349,24 +359,31 @@ <h1 style="display: flex; align-items: center;">
349359 var gradientLength = maxX - minX + 1 ;
350360
351361 elmnt . onmousedown = dragMouseDown ;
362+ elmnt . ontouchstart = dragMouseDown ;
352363
353364 function dragMouseDown ( e ) {
354365 removeTrashcan ( event )
355366 e = e || window . event ;
356- e . preventDefault ( ) ;
367+ var isTouch = e . type . startsWith ( 'touch' ) ;
368+ if ( ! isTouch ) e . preventDefault ( ) ;
357369 // get the mouse cursor position at startup:
358- mousePos = e . clientX ;
370+ mousePos = isTouch ? e . touches [ 0 ] . clientX : e . clientX ;
359371 d . onmouseup = closeDragElement ;
372+ d . ontouchcancel = closeDragElement ;
373+ d . ontouchend = closeDragElement ;
360374 // call a function whenever the cursor moves:
361375 d . onmousemove = elementDrag ;
376+ d . ontouchmove = elementDrag ;
362377 }
363378
364379 function elementDrag ( e ) {
365380 e = e || window . event ;
366- e . preventDefault ( ) ;
381+ var isTouch = e . type . startsWith ( 'touch' ) ;
382+ if ( ! isTouch ) e . preventDefault ( ) ;
367383 // 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 ;
370387 mousePosInGradient = mousePos - ( minX + 1 )
371388
372389 truePos = Math . round ( ( mousePosInGradient / gradientLength ) * 256 ) ;
@@ -393,7 +410,10 @@ <h1 style="display: flex; align-items: center;">
393410 function closeDragElement ( ) {
394411 /* stop moving when mouse button is released:*/
395412 d . onmouseup = null ;
413+ d . ontouchcancel = null ;
414+ d . ontouchend = null ;
396415 d . onmousemove = null ;
416+ d . ontouchmove = null ;
397417 }
398418 }
399419
0 commit comments