user823527
user823527

Reputation: 3712

Document height percentage of original height

I'd like to reset the height of the original document to remove extra space after elements are added. The code I have now is this.

    $(document).ready(function() {
       var document_height = $(document).height();
       document_height = 0.70 * document_height;
       $(document).height(document_height);
    });

This should change the document height but doesn't. Is there a better way to do this?

Upvotes: 3

Views: 104

Answers (2)

user823527
user823527

Reputation: 3712

The code in the original question does work. Something else was adding more space to the document.

Upvotes: 0

Patrick Moore
Patrick Moore

Reputation: 13354

I think you need to be using $(window) in place of $(document).

$(document) refers to height of the entire document, $(window) refers to the viewport size.

If you do indeed want the behavior for reducing height of the document object, you might consider alternatives in CSS to remove the margin/padding that is the "extra space" after the elements are added.

Upvotes: 3

Related Questions