Merge pull request #30277 from andreiho/smooth-scroll

[smooth-scroll] Add type definitions
This commit is contained in:
Armando Aguirre
2018-11-06 12:12:15 -08:00
committed by GitHub
5 changed files with 159 additions and 0 deletions
+68
View File
@@ -0,0 +1,68 @@
// Type definitions for smooth-scroll 14.2
// Project: https://github.com/cferdinandi/smooth-scroll
// Definitions by: Andrei Horodinca <https://github.com/andreiho>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
export as namespace SmoothScroll;
export = SmoothScroll;
declare namespace SmoothScroll {
type Easing =
| "Linear"
| "easeInQuad"
| "easeInCubic"
| "easeInQuart"
| "easeInQuint"
| "easeInOutQuad"
| "easeInOutCubic"
| "easeInOutQuart"
| "easeInOutQuint"
| "easeOutQuad"
| "easeOutCubic"
| "easeOutQuart"
| "easeOutQuint";
interface Options {
// Selectors
ignore?: string;
header?: string;
topOnEmptyHash?: boolean;
// Speed & Easing
speed?: number;
clip?: boolean;
offset?:
| number
| ((
anchor?: Element | number | null,
toggle?: Element | null
) => number);
easing?: Easing;
customEasing?: (time: number) => number;
// History
updateURL?: boolean;
popstate?: boolean;
// Custom Events
emitEvents?: boolean;
}
}
declare class SmoothScroll {
constructor(selector?: string, options?: SmoothScroll.Options);
init(options?: SmoothScroll.Options): void;
destroy(): void;
animateScroll(
anchor: Element | number | null,
toggle?: Element | null,
options?: SmoothScroll.Options
): void;
cancelScroll(noEvent?: boolean): void;
}
@@ -0,0 +1,34 @@
// Initialize and destroy SmoothScroll
const example1 = new SmoothScroll('a[href*="#"]', {
ignore: ".ignore",
header: '[data-scroll="header"]',
topOnEmptyHash: false,
speed: 1000,
clip: true,
offset: () => 10,
easing: "easeInCubic",
customEasing: () => 50,
updateURL: false,
popstate: false,
emitEvents: false
});
example1.destroy();
// Scrolling to an anchor
const example2 = () => {
const scroll = new SmoothScroll();
const anchor = document.querySelector("#bazinga");
scroll.animateScroll(anchor, null, { speed: 1000 });
};
// Scrolling to a specific Y-position
const example3 = () => {
const scroll = new SmoothScroll('a[href*="#"]');
scroll.animateScroll(750);
};
// Cancel scroll
const example4 = () => {
const scroll = new SmoothScroll();
scroll.cancelScroll();
};
@@ -0,0 +1,36 @@
import SmoothScroll = require("smooth-scroll");
// Initialize and destroy SmoothScroll
const example1 = new SmoothScroll('a[href*="#"]', {
ignore: ".ignore",
header: '[data-scroll="header"]',
topOnEmptyHash: false,
speed: 1000,
clip: true,
offset: () => 10,
easing: "easeInCubic",
customEasing: () => 50,
updateURL: false,
popstate: false,
emitEvents: false
});
example1.destroy();
// Scrolling to an anchor
const example2 = () => {
const scroll = new SmoothScroll();
const anchor = document.querySelector("#bazinga");
scroll.animateScroll(anchor, null, { speed: 1000 });
};
// Scrolling to a specific Y-position
const example3 = () => {
const scroll = new SmoothScroll('a[href*="#"]');
scroll.animateScroll(750);
};
// Cancel scroll
const example4 = () => {
const scroll = new SmoothScroll();
scroll.cancelScroll();
};
+20
View File
@@ -0,0 +1,20 @@
{
"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",
"test/smooth-scroll-global.test.ts",
"test/smooth-scroll.test.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }