PageSourceSearch

https://tj-research.com/js/scrolltopcontrol.js

js tj-research.com collected 2026-10-08 00:00:38 UTC 4,600 bytes, 99 lines download raw bytes

1//** jQuery Scroll to Top Control script- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com.
2//** Available/ usage terms at http://www.dynamicdrive.com (March 30th, 09')
3//** v1.1 (April 7th, 09'):
4//** 1) Adds ability to scroll to an absolute position (from top of page) or specific element on the page instead.
5//** 2) Fixes scroll animation not working in Opera. 
6var scrolltotop = {
7    //startline: Integer. Number of pixels from top of doc scrollbar is scrolled before showing control
8    //scrollto: Keyword (Integer, or "Scroll_to_Element_ID"). How far to scroll document up when control is clicked on (0=top).
9    setting: {
10        startline: 100,
11        scrollto: 0,
12        scrollduration: 1000,
13        fadeduration: [1000, 1000]
14    },
15    controlHTML: '<p class="pagetop"><i class="fa fa-arrow-circle-o-up fa-4x"></i></p>',
16    //HTML for control, which is auto wrapped in DIV w/ ID="topcontrol"
17    controlattrs: {
18        offsetx: 50,
19        offsety: 20
20    },
21    //offset of control relative to right/ bottom of window corner
22    anchorkeyword: '#top',
23    //Enter href value of HTML anchors on the page that should also act as "Scroll Up" links
24    state: {
25        isvisible: false,
26        shouldvisible: false
27    },
28    scrollup: function() {
29        if (!this.cssfixedsupport) //if control is positioned using JavaScript
30        this.$control.css({
31            opacity: 0
32        }) //hide control immediately after clicking it
33        var dest = isNaN(this.setting.scrollto) ? this.setting.scrollto : parseInt(this.setting.scrollto)
34        if (typeof dest == "string" && jQuery('#' + dest).length == 1) //check element set by string exists
35        dest = jQuery('#' + dest).offset().top
36        else dest = 0
37        this.$body.animate({
38            scrollTop: dest
39        }, this.setting.scrollduration);
40    },
41    keepfixed: function() {
42        var $window = jQuery(window)
43        var controlx = $window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx
44        var controly = $window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety
45        this.$control.css({
46            left: controlx + 'px',
47            top: controly + 'px'
48        })
49    },
50    togglecontrol: function() {
51        var scrolltop = jQuery(window).scrollTop()
52        if (!this.cssfixedsupport) this.keepfixed()
53        this.state.shouldvisible = (scrolltop >= this.setting.startline) ? true : false
54        if (this.state.shouldvisible && !this.state.isvisible) {
55            this.$control.stop().animate({
56                opacity: 1
57            }, this.setting.fadeduration[0])
58            this.state.isvisible = true
59        } else if (this.state.shouldvisible == false && this.state.isvisible) {
60            this.$control.stop().animate({
61                opacity: 0
62            }, this.setting.fadeduration[1])
63            this.state.isvisible = false
64        }
65    },
66    init: function() {
67        jQuery(document).ready(function($) {
68            var mainobj = scrolltotop
69            var iebrws = document.all
70            mainobj.cssfixedsupport = !iebrws || iebrws && document.compatMode == "CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
71            mainobj.$body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body')
72            mainobj.$control = $('<div id="topcontrol">' + mainobj.controlHTML + '</div>').css({
73                position: mainobj.cssfixedsupport ? 'fixed' : 'absolute',
74                bottom: mainobj.controlattrs.offsety,
75                right: mainobj.controlattrs.offsetx,
76                opacity: 0,
77                cursor: 'pointer'
78            }).attr({
79                title: 'Scroll Back to Top'
80            }).click(function() {
81                mainobj.scrollup();
82                return false
83            }).appendTo('body')
84            if (document.all && !window.XMLHttpRequest && mainobj.$control.text() != '') //loose check for IE6 and below, plus whether control contains any text
85            mainobj.$control.css({
86                width: mainobj.$control.width()
87            }
87) //IE6- seems to require an explicit width on a DIV containing text
88            mainobj.togglecontrol()
89            $('a[href="' + mainobj.anchorkeyword + '"]').click(function() {
90                mainobj.scrollup()
91                return false
92            })
93            $(window).bind('scroll resize', function(e) {
94                mainobj.togglecontrol()
95            })
96        })
97    }
98}
99scrolltotop.init()

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.