jQuery plugin: Fullscreen Background

If you’re a webdeveloper or designer I am pretty sure you’ve run into the problem of people wanting to have “fullscreen content” or just background images that will stretch in the most optimal way to the users screen.
Lately I found that a lot of people are asking for fullscreen backgrounds, videos and other types on stuff. So to prevent myself from reinventing the wheel over and over again I made a small jQuery plugin, and thought you guys might like it too.

So here it is: Fullscreen Background for jQuery.

jQuery plugin: Fullscreen Background

Download Download from GitHub Example Look at the goods

How to use.

And using it is so easy; anyone can do it!

Oh, and it works in every browser I could test it in. (IE7 and higher, Firefox, Opera, Safari and Chrome)

Here’s a short step by step installation guide:

  1. Put the following code in the <head> section of your webpage:

    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="jquery.fullscreenBackground.js"></script>
  2. Have the following structure in your HTML (or something similar):

    <div class="content">
        Content goes here
    </div>
    <div id="background-image">
        <img src="path/to/img.jpg" alt="" width="800" height="600" />
    </div>
  3. Remember to define the width and height of the images! This is important.
  4. Then, in your CSS. Make sure the content (not the background image container) is absolute and has a higher z-index than 1.
  5. Finally add this in a piece of Javascript, preferably in $(document).ready();

    $("#background-image").fullscreenBackground();

Documentation:

Fullscreen Background: Options

fullscreenBackground ( object options );

The plugin allows a few settings to give to the function:

options
string selector The selector that will be used when digging through the element you’re calling the function on. Default: "img"
bool fillOnResize Set to true if the image has to resize to the screen if the screensize changes. I think most will leave this set to true. Default: true
bool defaultCss Set to true if you want to add some standard CSS to the elements. If you are experiencing problems you can set this to false and do the CSS in your own stylesheet. Default: true

Conclusion:

Quick and easy: it really does the trick here.

Absolutely no rocket science, but it will prevent you from coding it again in the future.

Let me know what you think!

Liked this article? Sharing is caring!

94 Comments on this subject

  1. Tony said:

    Hi, thank you for sharing this useful plugin, Could you explain me please, how to center the div with the text? I mean, i want it to be placed exactly in the middle even if the resolution changes…

    thank you for the help

    Tony

  2. Matt Magi said:

    Been looking for a lightweight version of the supersized plugin that is strictly just for a background image found lots but they were all dated back to 2010-2011, glad I stumbled across this its going to work perfect!

  3. Magnus said:

    hi!
    This is really great plugin :) big thx!
    I have one problem though..
    i think its my css that is the problem, but anyway, il have to ask you..
    This should work fine on mobile devices such as iphone right? :)

  4. Larry said:

    About 145px of my image cuts off from the top. I noticed it does the same thing on your example too. Is there anyway to properly display my image from the top and left?

  5. Casey said:

    I’ve got to say, I love this. It was easy to use and works great! I have one question though, is there a way to use this for dynamically resizing a php file? My header is php and I’d like for it to resize along with the background for different screen resolutions.

  6. Vince said:

    Great script! I need my image to anchor on the top right corner, the script by default anchors it with the top left. I’m not very familiar with JS, so how would I modify it so that when the window shrinks, the top right of the image is still in the viewport? Thanks

  7. Enache said:

    Great little piece of work, i need to ask you if it’s posibile to have more than one background like this on a page to resize like that, i mean to have two div one on top of either. Thanks in advance

  8. Claes said:

    Me too have the same problem. I’ve done a page with a long scroll and I have backgroundimages in a couple of div’s that I want to be resized when window is resized.

  9. Marcus said:

    Hi I’m looking for a script that makes the image fullscreen, but only in the browser, not the full screen. I noticed in your script that the bottom and the top gets cut off due to the image stretching to the full monitors dimensions, not the browsers.. Is there a fix for this? My problem is that I have some elements in the bottom of the image im trying to use that isnt visible, the toolbar is covering that part..
    Any help is appreciated!

  10. paul said:

    Is there a way to use multiple background images in various divs? I’ve added two divs (as such in parallax sites), however the second div positions on top of the first, and yet that “section” of the page has not scrolled into view ..

Leave your reply

Your email address will not be published. Avatars through Gravatar.

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>