Tuesday, July 10, 2012

Fullscreen Background - jQuery plugin

 

 

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:
    1
    2
    3
    <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):
    1
    2
    3
    4
    5
    6
    <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();
    1
    $("#background-image").fullscreenBackground();

The options!

The plugin allows a few settings to give to the function:
selector (default: “img”)
The selector that will be used when digging through the element you’re calling the function on.
fillOnResize (default: true)
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.
defaultCss (default: true)
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.

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!



0 comments: