Resize on div element

前端 未结 11 1369
既然无缘
既然无缘 2020-11-28 08:31

jQuery has the resize() - event, but it just work with window.

jQuery(window).resize(function() { /* What ever */ });

This wor

11条回答
  •  情深已故
    2020-11-28 08:57

    I was only interested for a trigger when a width of an element was changed (I don' care about height), so I created a jquery event that does exactly that, using an invisible iframe element.

    $.event.special.widthChanged = {
      remove: function() {
          $(this).children('iframe.width-changed').remove();
      },
      add: function () {
          var elm = $(this);
          var iframe = elm.children('iframe.width-changed');
          if (!iframe.length) {
              iframe = $('