Image 01 Image 02

jQuery object positioning

Posted on 20th August 2008 by Sebastian
0


I’ve been fiddling a bit with jQuery for a small project of mine,* and ended up needing to position an element somewhere on the screen. This gets fiddly in CSS when you don’t know the exact size of the element, but in jQuery, it’s a breeze. At least with my little plugin.
It’s easy as pie to use on your jQuery site, you just:

  1. Download jQuery_centerOn.js to the js folder on your site.
  2. Add the following code to the <head> of the page you wish to use it on:
    <script type="text/javascript" src="js/jQuery_centerOn.js"/>
  3. Use the following command to position the element in question:
    $('#testThing').centerOn(300,200);

    In this example you would center the element with id testThing on the point (300,200).

That’s all there is to it!



Leave a reply...