Block mouse scroll in Javascript

Asked

Viewed 154 times

1

I made a program using Polymer and within one of the components in a specific area (the caption area of my chart) I want the scroll of the page not to work, is there any way to do this?

1 answer

3


You can hide the scroll when the mouse passes in a certain area, in my example I put to hide the overflow while passing the <div id="azul">.

var azul = document.getElementById("azul");

azul.onmouseover = function(){
   document.body.style.overflowY = "hidden";
};

azul.onmouseout = function(){
   document.body.style.overflowY = "auto";
};
#total{
  height: 900px;
}

#amarela{
  background-color: yellow;
  height:50%;
}

#azul{
  background-color: blue;
  height:50%;
}
<div id="total">
  <div id="amarela"></div>
  <div id="azul"></div>
</div>

Source: https://stackoverflow.com/questions/7915882/disabling-mouse-scrolling

  • So caique, I had seen some answers to similar questions the way Voce spoke, but in executing this is the return I have: "Uncaught Referenceerror: $ is not defined", I think it is due to being using Polymer, which makes me operating in shadow dom

  • This error is because the solution I posted uses the Jquery library and it needs to be included in order to work: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

  • I changed my answer so she no longer depends on jquery see if it helps you ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.