프로그램 개발서

pointer 이벤트를 통한 스크롤 처리 본문

Javascript

pointer 이벤트를 통한 스크롤 처리

rairen 2023. 6. 30. 16:55

 

let sliderList = document.querySelectorAll('.pointer-scroll');
sliderList.forEach(function(item) {
    let x;
    let y;
    let flag = false;
    item.onpointerdown = function(event){
    	event.preventDefault();
        x = event.clientX;
        y = event.clientY;
        flag = true;
    }
    item. onpointermove = function(event){
    	if(flag){
            item.scrollLeft += (-1 * (event.clientX - x));
            item.scrollTop += (-1 * (event.clientY - y));
            x = event.clientX;
            y = event.clientY;
        }
    }
    item.onpointerup = function(event){
    	flag = false;
    }
    item.ondragstart = () => false;
});

 

 

반응형