Skip to content

Plugin that aim to provide an efficient way to observe the size of DOM elements

License

Notifications You must be signed in to change notification settings

gestixi/size-observer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Size Observer

Simple plugin that aim to provide an efficient way to observe the size of DOM elements.


Installation

Size Observer depends on jQuery. To use it, include this in your page :

<script src="jquery.js" type="text/javascript"></script>
<script src="size-observer.js" type="text/javascript"></script>

Usage

To use this plugin you can directly specify a callback as first parameter. It will be call each time the size of the element changes.

You can also specify the properties to observes height or width as first parameter, and the callback as second parameter.

Example :
$(function() {
  $('img').onResize(function() {
    console.log('The size of this element changed: ', this);
  });

  // Same as:

  $('img').onResize(['height', 'width'], function() {
    console.log('The size of this element changed: ', this);
  });


  // Only check the height:

  $(document).onResize('height', function() {
    console.log('The height of the document changed: ', this);
  });


  // Only check the width:

  $(window).onResize('width', function() {
    console.log('The width of the window changed: ', this);
  });
});

Author

Nicolas Badia


Copyright and license

Copyright 2012-2018 GestiXi under The MIT License (MIT).

About

Plugin that aim to provide an efficient way to observe the size of DOM elements

Resources

License

Stars

Watchers

Forks

Packages

No packages published