Smooth Scroll doesn't work when I set the html and body height to 100%

html, body {
   height: 100%;
   min-height: 100%;
   position: relative;

#home {
   height: 100%;
   background: url("../img/test.jpg") center no-repeat;
   background-size: cover;

I'm using the Smooth Scroll JavaScript from CSS-Tricks

$(function() {
  $('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
      if (target.length) {
          scrollTop: target.offset().top
        }, 1000);
        return false;

The first section of the page it's a full page image, so I need the html and body to have a height of 100% to set the #home height to 100% too but for some reason when I do this the Smooth Scroll effect doesn't work and when I remove the height: 100% from html and body it does work.

Anyone with the same problem?


Use min-height: 100% instead of height: 100%.

The reason it's not working is because the page thinks that there is nowhere to scroll. Setting the html/body to 100% makes the page act like a giant frame, and you are scrolling in that frame rather than the actual document. Thus smooth scrolling will not work as you want it to.

The only workaround that I know of is using jQuery, rather than direct CSS, to set your div height to page width:

var windheight = $(window).height();

This might help. Very useful link.

Need Your Help

SwingWorker Interrupting Threads

java multithreading swingworker

I'm building an application where I'll have a SwingWorker thread that in itself spins off multiple worker threads. While these children threads do their work, what I want to achieve is that when the

Cannot find the user '', because it does not exist or you do not have permission

sql-server tsql sql-server-2005 stored-procedures

I am trying to add permissions to a Store procedure for a user using this query,