-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.heightControl.js
More file actions
37 lines (29 loc) · 1.07 KB
/
Copy pathjquery.heightControl.js
File metadata and controls
37 lines (29 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* Контроль изменения высоты блока.
* https://github.com/mavsan/heightControl
* Created by mavsan on 07.06.2016.
* Author: Maksim Klimenko
* Email: mavsan@gmail.com
*/
(function($){
jQuery.fn.heightControl = function(callback){
function main() {
var el = $(this),
lastHeight = el.height(),
newHeight = lastHeight;
callback = typeof callback == 'undefined' ? $.noop : callback;
(function run(){
newHeight = el.height();
if( lastHeight != newHeight ) {
callback(lastHeight, newHeight);
el.trigger('heightChanged', [lastHeight, newHeight]);
lastHeight = newHeight;
}
if( el.onElementHeightChangeTimer )
clearTimeout(el.onElementHeightChangeTimer);
el.onElementHeightChangeTimer = setTimeout(run, 200);
})();
}
return this.each(main);
};
})(jQuery);