layerAdjustment.js
1.78 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _utils = require('../utils/utils');
var _utils2 = _interopRequireDefault(_utils);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var __autoAdjustment__events__ = [];
exports.default = {
methods: {
layerAdjustmentOnce: function layerAdjustmentOnce(layerElement, targetElement, distance) {
var viewportOffset = _utils2.default.getViewportOffset(targetElement),
layerElemHeight = typeof layerElement.getBoundingClientRect !== "undefined" ? layerElement.getBoundingClientRect().height : layerElement.clientHeight;
if (viewportOffset.bottom < layerElemHeight) {
layerElement.style.top = viewportOffset.top - layerElemHeight - distance + 'px';
} else {
layerElement.style.top = viewportOffset.top + targetElement.clientHeight + distance + 'px';
}
layerElement.style.left = viewportOffset.left + 'px';
},
layerAdjustmentBind: function layerAdjustmentBind(layerElement, targetElement, distance) {
var _this = this;
var handler = function handler(e) {
setTimeout(function (x) {
_this.layerAdjustmentOnce(layerElement, targetElement, distance);
});
};
__autoAdjustment__events__.push(handler);
_utils2.default.bind(window, 'scroll', handler);
_utils2.default.bind(window, 'resize', handler);
}
},
beforeDestroy: function beforeDestroy() {
_utils2.default.unbind(window, 'scroll', __autoAdjustment__events__);
_utils2.default.unbind(window, 'resize', __autoAdjustment__events__);
}
};