[new feature] add sticky component (#3888)

This commit is contained in:
neverland
2019-07-18 17:48:18 +08:00
committed by GitHub
parent e1021e70ba
commit b273c89b3a
23 changed files with 651 additions and 124 deletions

View File

@@ -23,7 +23,7 @@ function getTouch(el: HTMLElement, x: number, y: number) {
// Trigger pointer/touch event
export function trigger(
wrapper: Wrapper<Vue> | HTMLElement,
wrapper: Wrapper<Vue> | HTMLElement | Window,
eventName: string,
x: number = 0,
y: number = 0,
@@ -80,3 +80,33 @@ export function mockGetBoundingClientRect(rect: ClientRect | DOMRect): Function
Element.prototype.getBoundingClientRect = originMethod;
};
}
export function mockHTMLElementOffset() {
Object.defineProperties(HTMLElement.prototype, {
offsetLeft: {
get() {
return parseFloat(window.getComputedStyle(this).marginLeft) || 0;
}
},
offsetTop: {
get() {
return parseFloat(window.getComputedStyle(this).marginTop) || 0;
}
},
offsetHeight: {
get() {
return parseFloat(window.getComputedStyle(this).height) || 0;
}
},
offsetWidth: {
get() {
return parseFloat(window.getComputedStyle(this).width) || 0;
}
}
});
}
export function mockScrollTop(value: number) {
Object.defineProperty(window, 'scrollTop', { value, writable: true });
trigger(window, 'scroll');
}