1)
let coords = {
left: 0,
x: 0
};
let isDragging = false;
function clickItems(event) {
coords = {
left: items.scrollLeft,
x: event.clientX
};
items.addEventListener('mousemove', dragItems);
items.addEventListener('mouseup', leaveItems);
isDragging = true;
}
function dragItems(event) {
const dx = coords.x - event.clientX;
items.scrollLeft = coords.left + dx;
}
function leaveItems() {
coords.left = items.scrollLeft;
// 클릭만 발생했을 경우 동영상 실행
if (!isDragging) {
openYouTube();
}
items.removeEventListener('mousemove', dragItems);
items.removeEventListener('mouseup', leaveItems);
isDragging = false;
}
HTML
복사