1

Hello all I was wondering if its possible to disable vertical mousewheel using jQuery. I can't use CSS because I have overflow that needs to be visible

$("#ab").bind("mousewheel", function() { //only effect scrolling to the right??
    return false;
});

thanks

Adam Konieska
  • 2,805
  • 3
  • 14
  • 27
Anfa A
  • 313
  • 2
  • 3
  • 9

2 Answers2

2

Possible duplicate? Copied directly from here: Disabling vertical scroll by mouse

$('#ab')
  .bind('mousewheel DOMMouseScroll', function(e) {
    e.preventDefault();
});

Or another one here: How to do a horizontal scroll on mouse wheel scroll?

var mouseWheelEvt = function (event) {
  if (document.body.doScroll)
    document.body.doScroll(event.wheelDelta>0?"left":"right");
  else if ((event.wheelDelta || event.detail) > 0)
    document.body.scrollLeft -= 10;
  else
    document.body.scrollLeft += 10;

  return false;
}
document.body.addEventListener("mousewheel", mouseWheelEvt);

Update: I think this is the exact code you're looking for:

$('#ab').bind('mousewheel DOMMouseScroll', function(e) {
  // Replace with != 0 if you want to prevent left/right instead.
  if (e.originalEvent.wheelDeltaX == 0) {
    e.preventDefault();
  }
});

Example: http://jsfiddle.net/32w276xL/

Community
  • 1
  • 1
Jonathan
  • 6,507
  • 5
  • 37
  • 47
  • no, im trying to disable the mouse wheel in only one direction(to the right) that and the script I included in my question disable the mouse wheel in all directions – Anfa A Mar 01 '15 at 04:34
  • Try the updated code, I think that's what you're looking for? – Jonathan Mar 01 '15 at 04:56
0

You can try it by this way....

HTML--

<div id='no_scroll'></div>

CSS--

body {
    height: 2000px;
}
#no_scroll{
    width: 50px;
    height: 1500px;
    background: blue;
}

jQuery--

$(document).ready(function(){
    $('body').on({
        'mousewheel': function(e) {
            if (e.target.id == 'no_scroll') return;
            e.preventDefault();
            e.stopPropagation();
        }
    }) 
});

The Demo

Sarower Jahan
  • 1,445
  • 1
  • 13
  • 20