Skip to content
Follow chrisiona on Twitter
4

FixedPosition > a jQuery Plugin

At Dodgers Stadium, LA
FixedPosition is a GoogleCode Project

What is Position: Fixed?

It’s a powerful CSS attribute, that allows you to fix a HTML element to a position on the page, irrespective of user interaction. Put simply, if the user scrolls, it stays put.

FixedPosition doesn’t jitter on scroll, it looks at capability (not user-agent), works in Internet Explorer 6, 7, 8 … about time huh.

What’s the Problem

As web developers (now let’s be honest), we face an interesting challenge when it comes to CSS and Internet Explorer. Did you know that IE7 & 8 only support fixed positioning when using a strict doctype? Quirks Mode still remains IE8’s default, meaning that we still need a graceful way of using this CSS gem.

Am I picking on IE?

Nah. I’m a big advocate for your right to choose a platform, device and browser. Heck, just read my article on Progressive Enhancement. This plug-in is all about delivering a consistent user experience (no matter the browser). It’s also about providing another tool to the cohort of web developers ( hi there ) to help make our career easier. Don’t forget, web development is considered the most hostile environment to develop software for..

How can we solve it?

Through a blend of CSS and JavaScript, we can gracefully achieve this functionality. That’s what this plug-in is all about.

Plug-in Features

  • Uses jQuery, a framework you already know
  • Support for IE6, 7 & 8
  • Integrates the IE Speed Fix to ensure a fluent user experience
  • It check for capability, not user-agent
  • Supports Standard and Quirks mode
  • Progressively Enhances your webpage

How to use it

  1. Download the jQuery framework
  2. Download the FixedPosition plug-in
  3. Observe the below example code

Example Code

<!--[if GTE IE 6]><!-->

<!-- The jQuery Framework -->
<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>

<!-- The FixedPosition plugin -->

<script src="jquery.fixedposition.1.0.0-min.js"></script>

<!-- Call the plugin on your jQuery object when the DOM is ready -->
<script>
  $(document).ready(function(){
     $(".fixedbar").fixedPosition({
        debug: true,
        fixedTo: "bottom",
        effect: "slideDown",
        effectSpeed: 200
     });
  });
</script>

<!--<![endif]-->;

Plugin Options:

  • fixedTo:            “top”, “bottom”
  • debug:               true, false
  • effect:                false, “fadeIn”, “slideDown”
  • effectSpeed:     Number

Tested On:

  • Internet Explorer 6.0.29 / WinXP
  • Internet Explorer 7.0.57 / WinXP
  • Internet Explorer 8.0.71 / Win7
  • Firefox 2.0.0.20 / WinXP
  • Google Chrome 3.0.195.38 / WinXP
  • Firefox 3.5.6 / OSX 10.5.8
  • Safari 4.0.4 / OSX 10.5.8
4 Comments Post a comment
  1. pbarney
    Apr 28 2010

    Can it be used to fix divs to the corners? E.g., top left, top right, bottom left, bottom right?

    Thanks

  2. kropotkin
    Dec 2 2010

    Didn’t work for me.

    we have

    …some inner content

    we currently have:

    .SocialLearnToolbarToolbar {white-space:nowrap;margin:0 auto;width:960px;position:fixed;bottom:0px;left:50%;margin-left:-480px;z-index:1000}

    and I tried:

    $(“.SocialLearnToolbarToolbar”).fixedPosition({
    debug: false,
    fixedTo: “bottom”,
    effect: “false”
    });

    - I get the correct debug info with debug set to true so the plugin is loaded.

    In IE8 and IE7 quirks mode before our bar was mostly off the page at the left and scrolling, not fixed. After applying the plugin it is now more on-screen and close to the bottom of the view-port when we load it – but still scrolls as soon as you use the scroll-bars.

    We are loading a ‘toolbar’ using a JS bookmarklet and the root element which we want fixed is added to the DOM dynamically. – after the plugin is added to jQuery but we don’t call the plugin method until a ready function indicates that the root element has been created.

    Any ideas?

    Thanks

    Justin Wyllie
    e. justinwyllie@hotmail.co.uk

  3. kropotkin
    Dec 3 2010

    The above problem was resolved.

    I have posted another problem on your Google code page http://code.google.com/p/fixedposition/issues/list

Trackbacks & Pingbacks

  1. FixedPosition > Get Position:Fixed working in IE « Chris Iona

Share your thoughts, post a comment.

You must be logged in to post a comment.