/
jqLite.js
46 lines (44 loc) · 1.17 KB
/
jqLite.js
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
38
39
40
41
42
43
44
45
46
(function(global) {
var jqLite = function(selector) {
if(selector && selector.length > 2 && selector[0] === '#') {
var elementId = selector.substring(1);
this.element = global.document.getElementById(elementId);
}
this.hide = function() {
this.element.style.display = 'none';
};
this.show = function() {
this.element.style.display = 'block';
};
this.getStyle = function(styleName) {
var styles = document.defaultView.getComputedStyle(this.element, '');
if(styles && styles[styleName]){
return styles[styleName];
}
};
this.getHeight = function() {
return parseInt(this.getStyle('height'));
};
this.setHeight = function(newHeight) {
this.element.style.height = newHeight + 'px';
};
this.slideDown = function(timeout) {
timeout = timeout || 500;
this.element.style.overflow = 'auto';
this.show();
var height = this.getHeight();
var that = this;
for (var i = 0; i < timeout; i++) {
var h = i / timeout * height;
(function(newHeight) {
setTimeout(function() {
that.setHeight(newHeight);
}, i);
})(h);
};
};
};
global.$ = function(selector) {
return new jqLite(selector);
};
})(window);