7
$('.news-wrap').mouseenter(function(event) {
    $(window).mousewheel(function(event) {
        event.preventDefault();
    });
});

Window scrolling is disabled, each I leave the element. How can I enable scrolling with mouseleave event?

3 Answers 3

9

I've written a jQuery plugin to handle this: $.disablescroll.

It stops scrolling from mousewheel, touchmove, and buttons such as Page Down.

$('.news-wrap').mouseenter(function() {

    $(window).disablescroll();

}).mouseleave(function() {

    $(window).disablescroll("undo");

});

Hope someone finds this helpful.

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

1 Comment

When I was dragging elements up or down and reached the scrollpoint of window, the mouse and draggable element were uncoupling. I tried this plugin and it worked like a charm...nice plugin
8

Like this?

$('#abs').bind('mousewheel DOMMouseScroll', function(e) {
    var scrollTo = null;
    if (e.type == 'mousewheel') {
        scrollTo = (e.originalEvent.wheelDelta * -1);
    } else if (e.type == 'DOMMouseScroll') {
        scrollTo = 1000 * e.originalEvent.detail;
    }

    if (scrollTo) {
        e.preventDefault();
        $(this).scrollTop(scrollTo + $(this).scrollTop());
    }
});​

Comments

0

I am currently using a plugin on bootstrap tour and the goal was to Disable scroll when clicking a link and enable it when you clicked an 'end tour' button in the tour.

In HTML create the div link by an id:

<div id='placeholder'><a href='#'>Placeholder link</a> </div>

Instantiate jquery with a click function.

start jquery:

$(document).ready(function() {
    /*click Function*/
    $('#placeholder').click(function(){
        /*Disables scrolling*/
        $('body').css('scroll', function(){
            window.scrollTo(0,0);
        });
    });  
});

Plugin option bootstrap tour when you end the popover:

/*This fire when clicking End Tour & placeholder would only work if that what you named the tour.*/
onEnd: function(placeholder) {
    /*Enable scroling*/
    $('body').css({ 'overflow': 'scroll' });
    $(document).off('scroll');
}

1 Comment

It's /*comment*/ instead of just comment in JavaScript ;)

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.