resize.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * @Describe: div大小监听事件
  3. */
  4. (function ($, h, c) {
  5. var a = $([]),
  6. e = $.resize = $.extend($.resize, {}),
  7. i,
  8. k = "setTimeout",
  9. j = "resize",
  10. d = j + "-special-event",
  11. b = "delay",
  12. f = "throttleWindow";
  13. e[b] = 250;
  14. e[f] = true;
  15. $.event.special[j] = {
  16. setup: function () {
  17. if (!e[f] && this[k]) {
  18. return false;
  19. }
  20. var l = $(this);
  21. a = a.add(l);
  22. $.data(this, d, {
  23. w: l.width(),
  24. h: l.height()
  25. });
  26. if (a.length === 1) {
  27. g();
  28. }
  29. },
  30. teardown: function () {
  31. if (!e[f] && this[k]) {
  32. return false;
  33. }
  34. var l = $(this);
  35. a = a.not(l);
  36. l.removeData(d);
  37. if (!a.length) {
  38. clearTimeout(i);
  39. }
  40. },
  41. add: function (l) {
  42. if (!e[f] && this[k]) {
  43. return false;
  44. }
  45. var n;
  46. function m(s, o, p) {
  47. var q = $(this),
  48. r = $.data(this, d);
  49. r.w = o !== c ? o : q.width();
  50. r.h = p !== c ? p : q.height();
  51. n.apply(this, arguments);
  52. }
  53. if ($.isFunction(l)) {
  54. n = l;
  55. return m;
  56. } else {
  57. n = l.handler;
  58. l.handler = m;
  59. }
  60. }
  61. };
  62. function g() {
  63. i = h[k](function () {
  64. a.each(function () {
  65. var n = $(this),
  66. m = n.width(),
  67. l = n.height(),
  68. o = $.data(this, d);
  69. if (m !== o.w || l !== o.h) {
  70. n.trigger(j, [o.w = m, o.h = l]);
  71. }
  72. });
  73. g();
  74. },
  75. e[b]);
  76. }
  77. })(jQuery, this);