Code Monkey home page Code Monkey logo

size-observer's Introduction

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).

size-observer's People

Contributors

nicolasbadia avatar

Watchers

 avatar  avatar  avatar

size-observer's Issues

Add a destroy method

This will be a breaking change as this should refer to the plugin and not the element:

$(window).resize(function() {
  this.destroy();
});

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.