Git Product home page Git Product logo

fillwindow.js's Introduction

FillWindow.js

A simple jQuery plugin to make a website section fill the browser window.

How do I use it?

Include jQuery and FillWindow.js in your webpage. Target an element or elements with fillWindow(). The elements that are shorter than the window's height will be resized to the height of the window on page load. (Elements that are already taller than the window won't be affected.)

Making it fully responsive

To make FillWindow fully responsive to window resize events, add something like the following to your $( document ).ready() function:

$( document ).ready( function() {
  function resizer() {
    $( '.element' ).fillWindow();
  }

  function startResize() {
    $( window ).resize( resizer );
  }

  function endResize() {
    $( window ).off( 'resize', resizer );
  }

  startResize();
  window.setTimeout( resizer, 75 );
} );

startResize() binds the window resize event handler. window.setTimeout( resizer, 75 ) fires fillWindow() once the document has loaded.

(Credit to http://stackoverflow.com/a/13268437/2140241 for the resizer()/startResize() idea.)

Options

By default, fillWindow() adds equal padding to the top and bottom of the target element to fit it to the window. fillWindow() takes an optional options object, which can include the following items:

alignment: the vertical alignment of the element's contents. alignment has possible values of null (which assigns equal padding to the top and bottom), top (which pushes content to the top of the element by assigning all padding to the bottom), and bottom (which pushes content to the bottom of the element using padding on the top). Default: null.

offset: the number of pixels larger or smaller than windowHeight to make the element. A negative number will make the element smaller than windowHeight by that number of pixels. A positive number will make the element larger than windowHeight by that number of pixels. (offset must be a number with no unit, or a function that returns a number with no unit). Default: 0.

Example usage:

$( '.element' ).fillWindow( { 
  alignment: 'bottom',
  offset: 20
} );

$( '.element2' ).fillWindow( { 
  offset: function() {
    return -( $( '#some-other-element' ).outerHeight() );
  }
} );

Examples

You can see the plugin in action at http://gordoncressy.com.

Changelog

1.2

  • Removed borderBox option. (Turns out it was unnecessary in the first place.)

TODO

  • Add option "resize". This would allow the user to bind FillWindow to the window resize event automatically, without having to write a handler themselves.

fillwindow.js's People

Contributors

jeradg avatar

Stargazers

Mikhail Shevtsov avatar

Watchers

James Cloos avatar  avatar Mikhail Shevtsov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.