File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed
2-ui/3-event-details/6-pointer-events/slider.view Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change 55 < div class ="thumb "> </ div >
66</ div >
77
8+ < p style ="border:1px solid gray " onmousemove ="this.textContent = new Date() "> Mouse over here to see the date</ p >
9+
810< script >
911 let thumb = slider . querySelector ( '.thumb' ) ;
1012 let shiftX ;
1113
12- thumb . onpointerdown = function ( event ) {
14+ function onThumbDown ( event ) {
1315 event . preventDefault ( ) ; // prevent selection start (browser action)
1416
1517 shiftX = event . clientX - thumb . getBoundingClientRect ( ) . left ;
1618
1719 thumb . setPointerCapture ( event . pointerId ) ;
20+
21+ thumb . onpointermove = onThumbMove ;
22+
23+ thumb . onpointerup = event => {
24+ // dragging finished, no need to track pointer any more
25+ // ...any other "drag end" logic here...
26+ thumb . onpointermove = null ;
27+ thumb . onpointerup = null ;
28+ }
1829 } ;
1930
20- thumb . onpointermove = function ( event ) {
31+ function onThumbMove ( event ) {
2132 let newLeft = event . clientX - shiftX - slider . getBoundingClientRect ( ) . left ;
2233
23- // если указатель находится за пределами слайдера => отрегулировать " left", чтобы оставаться в пределах границ
34+ // if the pointer is out of slider => adjust left to be within the boundaries
2435 if ( newLeft < 0 ) {
2536 newLeft = 0 ;
2637 }
3243 thumb . style . left = newLeft + 'px' ;
3344 } ;
3445
46+ thumb . onpointerdown = onThumbDown ;
47+
3548 thumb . ondragstart = ( ) => false ;
3649
3750</ script >
You can’t perform that action at this time.
0 commit comments