This commit is contained in:
Kiritan Flux 2018-12-05 13:22:41 +01:00
parent 05cf48534a
commit 83558f7bce
173 changed files with 1289 additions and 9312 deletions

View file

@ -1,25 +1,33 @@
# getSize
Get the size of elements.
Get the size of elements. Used in [Masonry](https://masonry.desandro.com), [Isotope](https://isotope.metafizzy.co), & [Flickity](https://flickity.metafizzy.co).
``` js
var size = getSize( elem );
// elem can be an element
var size = getSize( document.querySelector('#selector') )
// elem can be a string, used as a query selector
var size = getSize('#selector')
var size = getSize( document.querySelector('.selector') )
// elem can be a selector string
var size = getSize('.selector')
```
Returns an object with: `width`, `height`, `innerWidth/Height`, `outerWidth/Height`, `paddingLeft/Top/Right/Bottom`, `marginLeft/Top/Right/Bottom`, `borderLeft/Top/Right/BottomWidth` and `isBorderBox`.
Returns an object with:
+ width, height
+ innerWidth, innerHeight
+ outerWidth, outerHeight
+ paddingLeft, paddingTop, paddingRight, paddingBottom
+ marginLeft, marginTop, marginRight, marginBottom
+ borderLeftWidth, borderTopWidth, borderRightWidth, borderBottomWidth
+ isBorderBox
Browser support: IE10+, Android 4.0+, iOS 5+, and modern browsers
## Install
Install with [Bower](http://bower.io): `bower install get-size`
Install with npm: `npm install get-size`
Install with [Bower](https://bower.io): `bower install get-size`
## Firefox hidden iframe bug
[Firefox has an old bug](https://bugzilla.mozilla.org/show_bug.cgi?id=548397) that occurs within iframes that are hidden with `display: none`. To resolve this, you can use alternate CSS to hide the iframe off-screen, with out `display: none`.
@ -34,4 +42,4 @@ Install with npm: `npm install get-size`
## MIT License
getSize is released under the [MIT License](http://desandro.mit-license.org/).
getSize is released under the [MIT License](https://desandro.mit-license.org/).

View file

@ -1,15 +1,17 @@
{
"name": "get-size",
"version": "2.0.2",
"main": "get-size.js",
"description": "measures element size",
"dependencies": {
},
"devDependencies": {
"qunit": "~1.10"
},
"main": "get-size.js",
"authors": [
"David DeSandro"
],
"license": "MIT",
"keywords": [
"size",
"DOM"
],
"homepage": "https://github.com/desandro/get-size",
"ignore": [
"test/",
"**/.*",
"package.json",
"node_modules",
@ -17,21 +19,5 @@
"test",
"tests",
"sandbox.html"
],
"homepage": "https://github.com/desandro/get-size",
"authors": [
"David DeSandro <desandrocodes@gmail.com>"
],
"moduleType": [
"amd",
"globals",
"node"
],
"keywords": [
"size",
"dom",
"width",
"height"
],
"license": "MIT"
]
}

View file

@ -1,20 +1,17 @@
/*!
* getSize v2.0.2
* getSize v2.0.3
* measure size of elements
* MIT license
*/
/*jshint browser: true, strict: true, undef: true, unused: true */
/*global define: false, module: false, console: false */
/* jshint browser: true, strict: true, undef: true, unused: true */
/* globals console: false */
( function( window, factory ) {
'use strict';
/* jshint strict: false */ /* globals define, module */
if ( typeof define == 'function' && define.amd ) {
// AMD
define( function() {
return factory();
});
define( factory );
} else if ( typeof module == 'object' && module.exports ) {
// CommonJS
module.exports = factory();
@ -89,7 +86,7 @@ function getStyle( elem ) {
if ( !style ) {
logError( 'Style returned ' + style +
'. Are you running this code in a hidden iframe on Firefox? ' +
'See http://bit.ly/getsizebug1' );
'See https://bit.ly/getsizebug1' );
}
return style;
}
@ -115,8 +112,8 @@ function setup() {
// -------------------------- box sizing -------------------------- //
/**
* WebKit measures the outer-width on style.width on border-box elems
* IE & Firefox<29 measures the inner-width
* Chrome & Safari measure the outer-width on style.width on border-box elems
* IE11 & Firefox<29 measures the inner-width
*/
var div = document.createElement('div');
div.style.width = '200px';
@ -128,10 +125,11 @@ function setup() {
var body = document.body || document.documentElement;
body.appendChild( div );
var style = getStyle( div );
// round value for browser zoom. desandro/masonry#928
isBoxSizeOuter = Math.round( getStyleSize( style.width ) ) == 200;
getSize.isBoxSizeOuter = isBoxSizeOuter;
getSize.isBoxSizeOuter = isBoxSizeOuter = getStyleSize( style.width ) == 200;
body.removeChild( div );
}
// -------------------------- getSize -------------------------- //