Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't scroll when body overflow: hidden and an fixed element

I want to hide my scrollbar, so i gave the body of my site overflow:hidden;
Now I want to have my menubar fixed on the top of my page, with position: fixed;

But when I put my menubar on fixed I can't scroll my whole page anymore with my scrollwheel.
Who knows an answer?

body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

This is working, but when i put a position: fixed; on my menu, i can't scroll anymore.

.menu {
    position: fixed;
    width: 100%;
    height: 50px;
}

I hope you understand my question.

like image 489
Dennis Avatar asked Sep 17 '13 07:09

Dennis


1 Answers

You can accomplish this using jquery.mousewheel.js plugin.

Here is a demo of your page using this plugin: http://jsfiddle.net/BQeWx/

Javascript:

$('html,body').bind('mousewheel',function(ev, delta) {
    var scrollTop = $(this).scrollTop();
    $(this).scrollTop(scrollTop-Math.round(delta * 1));
});

CSS:

body, html { overflow: hidden; }

.body_wrapper {
    overflow: hidden;
    margin: 0; 
    padding: 0;
    width: 100%; 
    height: 100%; 
}

.wrapper {
    width: 100%;
    margin: 48px auto 0 auto;
    z-index: 10;
}

I've had to make a few modifications to your CSS which are noted in the comments.

If this is the intended user experience, you should consider adding a fixed 'return to top' link that appears off to the side or bottom of each section.

Documentation for plugin: https://github.com/brandonaaron/jquery-mousewheel

Hope this helps, cheers.

like image 102
Mat Bloom Avatar answered Dec 01 '22 07:12

Mat Bloom