Giter Site home page Giter Site logo

jqdim's Introduction

jqDim

Provide the traditional dimension methods as jQuery Slim.

It is suggested to use it with Vanilla JS, Bliss, or Cash.

Remarks: jQuery's implementation on dimension APIs is very nice!

Options

jQuery 3.5.1 (default)

  • jqDim.reliableTrDimensionsVer = 1

jQuery 3.6.0 ~ 3.7.1 (see jquery/jquery#5270)

  • jqDim.reliableTrDimensionsVer = 2

Usage

<script src="https://cdn.jsdelivr.net/gh/cyfung1031/[email protected]/release/jqDim-3.7.1.min.js"></script>


<a href="javascript:void(0);" onclick="ShowElementDimensions();">Show element dimensions</a>
<div id="divTestArea1" style="height: 100px; width: 400px; padding: 20px; margin: 3px; border: 1px solid silver; background-color: #eee;"></div>

<script type="text/javascript">
function ShowElementDimensions()
{
  
    let elm = document.querySelector("#divTestArea1")
	var result = "";

    let dim = window.jqDim(elm)
	
	result += "Dimensions of div: " + dim.width() + "x" + dim.height() + "</br>";
	result += "Inner dimensions of div: " + dim.innerWidth() + "x" + dim.innerHeight() + "</br>";	
	result += "Outer dimensions of div: " + dim.outerWidth() + "x" + dim.outerHeight() + "</br>";	
	result += "Outer dimensions of div (with margin): " + dim.outerWidth(true) + "x" + dim.outerHeight(true) + "</br>";	
	
	(elm).innerHTML=result;
    
}
</script>

File Size Reference

Size jDim 3.6.0 Bliss Cash 8.1.0 jQuery Slim 3.6.0
Unminified 27.1 KB 21.1 KB 36.5 KB 229 KB
Minified 5.97 KB 10.7 KB 16 KB 70.6 KB
Minified & Gzipped 2.59 KB 3 KB 6 KB 24.4 KB
Size jDim + Bliss jDim + Cash jQuery Slim 3.6.0
Unminified 48.2 KB 57.6 KB 229 KB
Minified 16.7 KB 22 KB 70.6 KB
Minified & Gzipped 5.59 KB 8.59 KB 24.4 KB

jqDim(element)'s methods [GET]

  • .offset()
  • .position()
  • .scrollTop()
  • .scrollLeft()
  • .width()
  • .height()
  • .innerWidth()
  • .innerHeight()
  • .outerWidth()
  • .outerHeight()
  • .outerWidth(true)
  • .outerHeight(true)

Browser Support

Edge Chrome Firefox IE Opera Safari
15+ ✔ 51+✔ 45+✔ 38+✔ 10+ ✔

Fix for Dimension Calculation in 3.7.1

Screen Shot 2024-03-25 at 19 24 47

License

This project is released under MIT License

Most source codes come from jQuery Slim v3.7.1

jQuery JavaScript Library v3.7.1 -ajax,-ajax/jsonp,-ajax/load,-ajax/script,-ajax/var/location,-ajax/var/nonce,-ajax/var/rquery,-ajax/xhr,-manipulation/_evalUrl,-deprecated/ajax-event-alias,-effects,-effects/Tween,-effects/animatedSelector

https://jquery.com/

Copyright OpenJS Foundation and other contributors

Released under the MIT license

https://jquery.org/license

Date: 2021-03-02T17:08Z

jqdim's People

Contributors

cyfung1031 avatar

Watchers

 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.