Giter VIP home page Giter VIP logo

jquery.actual's Introduction

jQuery Actual Plugin

Get the actual width/height of invisible DOM elements with jQuery.

Description

jQuery has trouble finding the width/height of invisible DOM elements. With element or its parent element has css property 'display' set to 'none'. $('.hidden').width(); will return 0 instead of the actual width; This plugin simply fix it.

Demo

  • Normal usage see demo/normal.html
  • If you use css3pie you might also want to take a look at another demo( demo/css3pie.html )
  • Live demo please take a look at this and this

Documentation

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

Requires

  • jQuery >= 1.2.3

Browser Compatibility

Installation

  • First, make sure you are using valid DOCTYPE
  • Include necessary 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.actual.js"></script>

Usage

Example code:

// get hidden element actual width
$( '.hidden' ).actual( 'width' );

// get hidden element actual innerWidth
$( '.hidden' ).actual( 'innerWidth' );

// get hidden element actual outerWidth
$( '.hidden' ).actual( 'outerWidth' );

// get hidden element actual outerWidth and set the `includeMargin` argument
$( '.hidden' ).actual( 'outerWidth', { includeMargin : true });

// get hidden element actual height
$( '.hidden' ).actual( 'height' );

// get hidden element actual innerHeight
$( '.hidden' ).actual( 'innerHeight' );

// get hidden element actual outerHeight
$( '.hidden' ).actual( 'outerHeight' );

// get hidden element actual outerHeight and set the `includeMargin` argument
$( '.hidden' ).actual( 'outerHeight', { includeMargin : true });

// if the page jumps or blinks, pass a attribute '{ absolute : true }'
// be very careful, you might get a wrong result depends on how you makrup your html and css
$( '.hidden' ).actual( 'height', { absolute : true });

// if you use css3pie with a float element
// for example a rounded corner navigation menu you can also try to pass a attribute '{ clone : true }'
// please see demo/css3pie in action
$( '.hidden' ).actual( 'width', { clone : true });

// if it is not a block element. By default { display: 'block' }.
// for example a inline element
$( '.hidden' ).actual( 'width', { display: 'inline-block' });

Credits

License

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

Copyright (c) 2012 Ben Lin

jquery.actual's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery.actual's Issues

Support native jquery-1.9

Looks like the parts that need to change are as follows:

  • jQuery.fn.andSelf() needs to change to jQuery.fn.addBack()
  • The demo depends on jQuery.browser, which is no longer supported / available, so this functionality could either depend on jquery-migrate, another library, or some native code. Since it just needs to check if the user agent is MSIE with major version < 7, perhaps it would be acceptable to perform this check natively?

Perhaps

  if( $.browser.msie && $.browser.version < 7 ){

could become

  if( typeof navigator.appName === "string" &&
        navigator.appName === "Microsoft Internet Explorer" &&
        parseFloat(navigator.userAgent.replace(new RegExp(".*MSIE\\D*(\\d+.\\d+).*"), "$1")) < 7
  ){

See http://msdn.microsoft.com/en-us/library/ms537509(v=vs.85).aspx

No access to properties

So i need to get the scrollHeight of a hidden element. But this isn't a function so it breaks.

Local variable "style" not initialized

Hi, I haven't tested this, but looking at your code, inside the else-branch, there is:

var ..., style;

fix = function (){
    // ...
    style += 'visibility: hidden !important; display: block !important; ';

This should result in style beeing 'undefinedvisibility: hidden ...' which is ruins the visibility-attribute - I guess that's not what you wanted.

Inverted code lines

I bet there is a mistake on the latest release.
Lines 60-61 should go prior line 59 ($this.css( css );)

btw, the plugin seems to still be useful if using jQuery Mobile, even with jQuery 1.7.2.
childs of hidden elements (display:none) return height/width = 0 using the default height()/width() function

Add git link

Suggestion , add a link to this repo in code comments. I found the old version in packed theme plugins file and by looking at this

/*! Copyright 2012, Ben Lin (http://dreamerslab.com/)
 * Licensed under the MIT License (LICENSE.txt).
 *
 * Version: 1.0.17
 *
 * Requires: jQuery >= 1.2.3
 */

I have no idea what the plugin is ( the method actual is ambiguous ) since the file was compiled about year ago and you have many repos.

this would be preferred

/*! Copyright 2012, Ben Lin (http://dreamerslab.com/)
 * Licensed under the MIT License (LICENSE.txt).
 * https://github.com/dreamerslab/jquery.actual
 * Version: 1.0.18
 *
 * Requires: jQuery >= 1.2.3
 */

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.