mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-01-30 05:27:30 +00:00
Add types for scroll (#37592)
* Add types for scroll * Remove tslint-rules and change version of the target * Fix linter errors
This commit is contained in:
parent
0069742408
commit
ce4df95708
45
types/scroll/index.d.ts
vendored
Normal file
45
types/scroll/index.d.ts
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
// Type definitions for scroll 3.0
|
||||
// Project: https://github.com/michaelrhodes/scroll
|
||||
// Definitions by: Roman Charugin <https://github.com/romic>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
type ScrollError = Error | null;
|
||||
|
||||
interface ScrollOptions {
|
||||
/**
|
||||
* Ease function
|
||||
* @default easeInOut
|
||||
*/
|
||||
ease?: (time: number) => number;
|
||||
/**
|
||||
* Animation duration
|
||||
* @default 350
|
||||
*/
|
||||
duration?: number;
|
||||
}
|
||||
|
||||
interface ScrollCallback {
|
||||
(error: ScrollError, value: number): void;
|
||||
}
|
||||
|
||||
interface Cancel {
|
||||
(): void;
|
||||
}
|
||||
|
||||
interface Scroll {
|
||||
/**
|
||||
* @param el Element to scroll
|
||||
* @param to Scroll to value
|
||||
* @param opts Additional options
|
||||
* @param cb Callback function to call after
|
||||
* @return Function to stop scrolling
|
||||
*/
|
||||
(el: HTMLElement, to: number, opts?: ScrollOptions | ScrollCallback, cb?: ScrollCallback): Cancel;
|
||||
}
|
||||
|
||||
declare const scroll: {
|
||||
left: Scroll;
|
||||
top: Scroll;
|
||||
};
|
||||
|
||||
export = scroll;
|
||||
23
types/scroll/scroll-tests.ts
Normal file
23
types/scroll/scroll-tests.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import scroll = require('scroll');
|
||||
|
||||
const el: HTMLElement = document.createElement('div');
|
||||
const opts = {
|
||||
duration: 1000,
|
||||
ease: (time: number) => 0.5 * time,
|
||||
};
|
||||
const cb: (error: Error | null, scrollValue: number) => void = (error, scrollValue) => {
|
||||
if (error != null) {
|
||||
console.error(error);
|
||||
} else {
|
||||
console.log('scrolling completed! current scroll position is ', scrollValue);
|
||||
}
|
||||
};
|
||||
|
||||
scroll.left(el, 500, opts, cb);
|
||||
scroll.top(el, 500, opts, cb);
|
||||
|
||||
scroll.left(el, 500, opts);
|
||||
scroll.top(el, 500, opts);
|
||||
|
||||
scroll.left(el, 500, cb);
|
||||
scroll.top(el, 500, cb);
|
||||
24
types/scroll/tsconfig.json
Normal file
24
types/scroll/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"scroll-tests.ts"
|
||||
]
|
||||
}
|
||||
3
types/scroll/tslint.json
Normal file
3
types/scroll/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user