PageSourceSearch

https://www.mac-forums.com/blog/wp-content/plugins/click-to-top/assets/js/jquery.scrollUp.js?ver=1.0

js mac-forums.com collected 2026-10-03 21:37:38 UTC 5,501 bytes, 168 lines download raw bytes

vendor: 5,501 bytes, lines 1-168
1/*!
2 * scrollup v2.4.1
3 * Url: http://markgoodyear.com/labs/scrollup/
4 * Copyright (c) Mark Goodyear — @markgdyr — http://markgoodyear.com
5 * License: MIT
6 */
7(function ($, window, document) {
8    'use strict';
9
10    // Main function
11    $.fn.scrollUp = function (options) {
12
13        // Ensure that only one scrollUp exists
14        if (!$.data(document.body, 'scrollUp')) {
15            $.data(document.body, 'scrollUp', true);
16            $.fn.scrollUp.init(options);
17        }
18    };
19
20    // Init
21    $.fn.scrollUp.init = function (options) {
22
23        // Define vars
24        var o = $.fn.scrollUp.settings = $.extend({}, $.fn.scrollUp.defaults, options),
25            triggerVisible = false,
26            animIn, animOut, animSpeed, scrollDis, scrollEvent, scrollTarget, $self;
27
28        // Create element
29        if (o.scrollTrigger) {
30            $self = $(o.scrollTrigger);
31        } else {
32            $self = $('<a/>', {
33                id: o.scrollName,
34                href: '#top'
35            });
36        }
37
38        // Set scrollTitle if there is one
39        if (o.scrollTitle) {
40            $self.attr('title', o.scrollTitle);
41        }
42
43        $self.appendTo('body');
44
45        // If not using an image display text
46        if (!(o.scrollImg || o.scrollTrigger)) {
47            $self.html(o.scrollText);
48        }
49
50        // Minimum CSS to make the magic happen
51        $self.css({
52            display: 'none',
53            position: 'fixed',
54            zIndex: o.zIndex
55        });
56
57        // Active point overlay
58        if (o.activeOverlay) {
59            $('<div/>', {
60                id: o.scrollName + '-active'
61            }).css({
62                position: 'absolute',
63                'top': o.scrollDistance + 'px',
64                width: '100%',
65                borderTop: '1px dotted' + o.activeOverlay,
66                zIndex: o.zIndex
67            }).appendTo('body');
68        }
69
70        // Switch animation type
71        switch (o.animation) {
72            case 'fade':
73                animIn = 'fadeIn';
74                animOut = 'fadeOut';
75                animSpeed = o.animationSpeed;
76                break;
77
78            case 'slide':
79                animIn = 'slideDown';
80                animOut = 'slideUp';
81                animSpeed = o.animationSpeed;
82                break;
83
84            default:
85                animIn = 'show';
86                animOut = 'hide';
87                animSpeed = 0;
88        }
89
90        // If from top or bottom
91        if (o.scrollFrom === 'top') {
92            scrollDis = o.scrollDistance;
93        } else {
94            scrollDis = $(document).height() - $(window).height() - o.scrollDistance;
95        }
96
97        // Scroll function
98        scrollEvent = $(window).scroll(function () {
99            if ($(window).scrollTop() > scrollDis) {
100                if (!triggerVisible) {
101                    $self[animIn](animSpeed);
102                    triggerVisible = true;
103                }
104            } else {
105                if (triggerVisible) {
106                    $self[animOut](animSpeed);
107                    triggerVisible = false;
108                }
109            }
110        });
111
112        if (o.scrollTarget) {
113            if (typeof o.scrollTarget === 'number') {
114                scrollTarget = o.scrollTarget;
115            } else if (typeof o.scrollTarget === 'string') {
116                scrollTarget = Math.floor($(o.scrollTarget).offset().top);
117            }
118        } else {
119            scrollTarget = 0;
120        }
121
122        // To the top
123        $self.click(function (e) {
124            e.preventDefault();
125
126            $('html, body').animate({
127                scrollTop: scrollTarget
128            }, o.scrollSpeed, o.easingType);
129        });
130    };
131
132    // Defaults
133    $.fn.scrollUp.defaults = {
134        scrollName: 'scrollUp',      // Element ID
135        scrollDistance: 300,         // Distance from top/bottom before showing element (px)
136        scrollFrom: 'top',           // 'top' or 'bottom'
137        scrollSpeed: 300,            // Speed back to top (ms)
138        easingType: 'linear',        // Scroll to top easing (see http://easings.net/)
139        animation: 'fade',           // Fade, slide, none
140        animationSpeed: 200,         // Animation in speed (ms)
141        scrollTrigger: false,        // Set a custom triggering element. Can be an HTML string or jQuery object
142        scrollTarget: false,         // Set a custom target element for scrolling to. Can be element or number
143        scrollText: 'Scroll to top', // Text for element, can contain HTML
144        scrollTitle: false,          // Set a custom <a> title if required. Defaults to scrollText
145        scrollImg: false,            // Set true to use image
146        activeOverlay: false,        // Set CSS color to display scrollUp active point, e.g '#00FFFF'
147        zIndex: 2147483647           // Z-Index for the overlay
148    };
149
150    // Destroy scrollUp plugin and clean all modifications to the DOM
151    $.fn.scrollUp.destroy = function (scrollEvent) {
152        $.removeData(document.body, 'scrollUp');
153        $('#' + $.fn.scrollUp.settings.scrollName).remove();
154        $('#' + $.fn.scrollUp.settings.scrollName + '-active').remove();
155
156        // If 1.7 or above use the new .off()
157        if ($.fn.jquery.split('.')[1] >= 7) {
158            $(window).off('scroll', scrollEvent);
159
160        // Else use the old .unbind()
161        } else {
162            $(window).unbind('scroll', scrollEvent);
163        }
164    };
165
166    $.scrollUp = $.fn.scrollUp;
167
168})(jQuery, window, document);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.