From dea8dc1a00c12289fbb4f68e8103620e1bf176fb Mon Sep 17 00:00:00 2001 From: Ben Dixon Date: Thu, 18 Jun 2015 15:09:37 +0100 Subject: [PATCH] Add definitions for ScrollToFixed https://github.com/bigspotteddog/ScrollToFixed --- scrolltofixed/scrolltofixed-tests.ts | 35 ++++++++++++++++++++++ scrolltofixed/scrolltofixed.d.ts | 43 ++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 scrolltofixed/scrolltofixed-tests.ts create mode 100644 scrolltofixed/scrolltofixed.d.ts diff --git a/scrolltofixed/scrolltofixed-tests.ts b/scrolltofixed/scrolltofixed-tests.ts new file mode 100644 index 0000000000..23b7873048 --- /dev/null +++ b/scrolltofixed/scrolltofixed-tests.ts @@ -0,0 +1,35 @@ +/// + +$(document).ready(function() { + $('#mydiv').scrollToFixed(); +}); + +$(document).ready(function() { + $('.header').scrollToFixed({ + preFixed: function() { $(this).find('h1').css('color', 'blue'); }, + postFixed: function() { $(this).find('h1').css('color', ''); } + }); + + $('.footer').scrollToFixed( { + bottom: 0, + limit: $('.footer').offset().top, + preFixed: function() { $(this).find('h1').css('color', 'blue'); }, + postFixed: function() { $(this).find('h1').css('color', ''); } + }); + + // Order matters because our summary limit is based on the position + // of the footer. On window refresh, the summary needs to recalculate + // after the footer. + $('#summary').scrollToFixed({ + marginTop: $('.header').outerHeight() + 10, + limit: function() { + var limit = $('.footer').offset().top - $('#summary').outerHeight(true) - 10; + return limit; + }, + zIndex: 999, + preFixed: function() { $(this).find('.title').css('color', 'blue'); }, + preAbsolute: function() { $(this).find('.title').css('color', 'red'); }, + postFixed: function() { $(this).find('.title').css('color', ''); }, + postAbsolute: function() { $(this).find('.title').css('color', ''); } + }); +}); \ No newline at end of file diff --git a/scrolltofixed/scrolltofixed.d.ts b/scrolltofixed/scrolltofixed.d.ts new file mode 100644 index 0000000000..2a1ef70a8d --- /dev/null +++ b/scrolltofixed/scrolltofixed.d.ts @@ -0,0 +1,43 @@ +// Type definitions for ScrollToFixed +// Project: https://github.com/bigspotteddog/ScrollToFixed +// Definitions by: Ben Dixon +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module ScrollToFixed { + interface ScrollToFixedOptions { + marginTop? : number | (() => number); + limit? : number | (() => number); + bottom?: number; + zIndex? : number; + spacerClass? : string; + preFixed?: () => void; + fixed?: () => void; + postFixed?: () => void; + preUnfixed?: () => void; + unfixed?: () => void; + postUnfixed?: () => void; + preAbsolute?: () => void; + postAbsolute?: () => void; + offsets? : boolean; + minWidth? : number; + maxWidth? : number; + dontCheckForPositionFixedSupport? : boolean; + dontSetWidth? : boolean; + removeOffsets? : boolean; + } +} + +interface JQuery { + isScrollToFixed(el: Element) : JQuery; + isScrollToFixed(el: Element[]) : JQuery; + isScrollToFixed(el: {}) : JQuery; + isScrollToFixed(el: JQuery) : JQuery; + ScrollToFixed(el : Element, options : ScrollToFixed.ScrollToFixedOptions) : JQuery; + ScrollToFixed(el: Element[], options : ScrollToFixed.ScrollToFixedOptions) : JQuery; + ScrollToFixed(el: {}, options : ScrollToFixed.ScrollToFixedOptions) : JQuery; + ScrollToFixed(el: JQuery, options : ScrollToFixed.ScrollToFixedOptions) : JQuery; + + scrollToFixed : (options? : ScrollToFixed.ScrollToFixedOptions) => JQuery[]; +} \ No newline at end of file