0

Im using vanilla JS and I am getting a really annoying issue where if you hover the scrollbar of an element that has a mouseleave event listener the mouseleave will be called.

However, if you use the mouse wheel to scroll before hovering the element you will then be able to interact with the scrollbar without any issue at all.

This is the javascript:

var mainMenu = document.getElementById("mainTable");

mainMenu.addEventListener("mouseleave", function(evt) {
    console.log("exited");
  });

This is the element

<table id="mainTable" style="overflow-y:scroll;">
   <tbody>
      <tr>1</tr>
      <tr>2</tr>
      <tr>3</tr>
      <tr>4</tr>
      <tr>5</tr>
      <tr>6</tr>
   </tbody>
</table>

I believed that mouseleave worked with direct descendants of the element with the listener, so even without having to scroll the first time the scrollbar should act as a descendant.

1 Answer 1

0

So to fix this I added in something to initialize the scrollbar

    var mainMenu = document.getElementById("mainTable");

    mainMenu.scroll(0,1);

    mainMenu.addEventListener("mouseleave", function(evt) {
      console.log("exited");
    });

This a bit of a bodge fix but currently working without an issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.