LoginSignup
6
9

More than 5 years have passed since last update.

要素のリサイズイベントを取得

Last updated at Posted at 2014-03-29

要素のリサイズイベントを取りたいが、jQueryだけでは出来ないみたいなので、探していたらこういうものを見つけた。

http://d.hatena.ne.jp/cyokodog/20101101/exresize01
https://github.com/cyokodog/jquery.ex-resize

ただ、このままだとjQuery1.9以降でエラーがでるみたいなので、その部分だけとりあえず動くようにしてみた。
この変更を入れると、古いブラウザに対応できなくなるのかな?
古いブラウザも対応する必要がある場合は、ここのブラウザ判定処理をそれ用に書き直せばいけると思う。

$.ex.resize = function(idx , targets , option){
    if ($.isFunction(option)) {
        option = {callback : option};
    }
    var o = this,
    c = o.config = $.extend({} , $.ex.resize.defaults , option);
    c.targets = targets;
    c.target = c.watchTarget = c.targets.eq(idx);
    c.index = idx;
    // ----------
    // c.oldBrowser = $.browser.msie && ($.browser.version < 8.0 || !$.boxModel);
    c.oldBrowser = false;
    // ----------
    c.key = { height : '', width : ''};
    if (c.contentsWatch) {
        o._createContentsWrapper();
    }
    c.currentSize = c.newSize = o.getSize();
    if (c.resizeWatch) o._resizeWatch();
}

使い方。

$("#elid").exResize(function() {
    // 処理
}
6
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
9