Giter Site home page Giter Site logo

jquery.center's Introduction

jQuery Center Plugin

A jQuery plugin that centralizes DOM element.

Description

This simple plugin helps you centralize your DOM element against their parent element or the window. You can also specify the top of the DOM element by passing customized settings. This plugin only works for absolute elements.

Demo

  • Please see demo.html
  • Live demo please take a look at this

Documentation

  • There is a syntax highlight version, please see this post
  • For chinese version please go here

Requires

  • jQuery 1.2.6+

Browser Compatibility

Installation

  • First, make sure you are using valid DOCTYPE
  • Include nessesary JS files
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
  <script type="text/javascript" src="path-to-file/jquery.center.js"></script>

Options

against

  • description: the element that the DOM element centralize against to
  • data type: string
  • default value: 'window'
  • possible value: 'window', 'parent', or '.someTarget'

top

  • description: you can specify the top of the target element
  • data type: integer
  • default value: false
  • possible value: 13, 20, 36 ... any number you want

topPercentage

  • description: or specify the top in percentage of the target element
  • data type: float
  • default value: 0.5
  • possible value: 0.1, 0.4, 0.8 ...

resize

  • description: center on window resize
  • data type: boolean
  • default value: true
  • possible value: true | false

Usage

Example code:

  // centralize #some-element against the window
  $( '#some-element' ).center();

  // centralize .some-element against its parent element
  $( '.some-element' ).center({
    against : 'parent',
    top     : 10
  });

  // centralize .some-element against '.some-target-element'
  // !IMPORTANT '.some-target-element' must be ".some-element"'s parents
  $( '.some-element' ).center({
    against       : '.some-target-element',
    topPercentage : 0.4
  });

License

The expandable plugin is licensed under the MIT License (LICENSE.txt).

Copyright (c) 2011 Ben Lin

jquery.center's People

Contributors

ben-lin avatar

Watchers

Max Barrass 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.