79789752

Date: 2025-10-14 02:19:57
Score: 0.5
Natty:
Report link

I found solution work for me. We have to handle inside iframe, not at parent website. The idea is: listen to wheel event of iframe document, if scroll position is top or bottom then preventDefault the wheel event. In my case, only div tag id message_list is overflow-auto, so I base on it to detect whether the scroll position is top or bottom. Hope this would help you all. My app is vue3 btw.

const handleWheel = (e) => {
  try {
    const el = document.getElementById('message_list');
    if (!el) {
      return;
    }
    const delta = e.deltaY;
    const atTop = el.scrollTop === 0;
    const atBottom = el.scrollTop + el.clientHeight >= el.scrollHeight;
    if ((delta < 0 && atTop) || (delta > 0 && atBottom)) {
      e.preventDefault();
    }
  } catch {
    //
  }
};

onMounted(() => {
  document.addEventListener('wheel', handleWheel, {
    passive: false,
  });
});

onMounted(() => {
  document.addEventListener('wheel', handleWheel, {
    passive: false,
  });
});
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Van Minh FPT