PageSourceSearch

https://gzlib.org.cn/r/cms/www/lasttemp/js/plugin/scrollbox/jquery.scrollbox.js

js gzlib.org.cn collected 2026-10-02 11:22:45 UTC 5,814 bytes, 173 lines download raw bytes

1/*!
2 * jQuery Scrollbox
3 * (c) 2009-2013 Hunter Wu <[email protected]>
4 * MIT Licensed.
5 *
6 * http://github.com/wmh/jquery-scrollbox
7 */
8(function($) {
9
10$.fn.scrollbox = function(config) {
11  //default config
12  var defConfig = {
13    linear: false,          // Scroll method
14    startDelay: 2,          // Start delay (in seconds)
15    delay: 3,               // Delay after each scroll event (in seconds)
16    step: 5,                // Distance of each single step (in pixels)
17    speed: 32,              // Delay after each single step (in milliseconds)
18    switchItems: 1,         // Items to switch after each scroll event
19    direction: 'vertical',
20    distance: 'auto',
21    autoPlay: true,
22    onMouseOverPause: true,
23    paused: false,
24    queue: null
25  };
26  config = $.extend(defConfig, config);
27  config.scrollOffset = config.direction === 'vertical' ? 'scrollTop' : 'scrollLeft';
28  if (config.queue) {
29    config.queue = $('#' + config.queue);
30  }
31  return this.each(function() {
32    var container = $(this),
33        containerUL,
34        scrollingId = null,
35        nextScrollId = null,
36        paused = false,
37        backward,
38        forward,
39        resetClock,
40        scrollForward,
41        scrollBackward;
42
43    if (config.onMouseOverPause) {
44      container.bind('mouseover', function() { paused = true; });
45      container.bind('mouseout', function() { paused = false; });
46    }
47    containerUL = container.children('ul:first-child');
48
49    scrollForward = function() {
50      if (paused) {
51        return;
52      }
53      var curLi,
54          i,
55          newScrollOffset,
56          scrollDistance,
57          theStep;
58
59      curLi = containerUL.children('li:first-child');
60
61      scrollDistance = config.distance !== 'auto' ? config.distance :
62        config.direction === 'vertical' ? curLi.height() : curLi.width();
63
64      // offset
65      if (!config.linear) {
66        theStep = Math.max(3, parseInt((scrollDistance - container[0][config.scrollOffset]) * 0.3, 10));
67        newScrollOffset = Math.min(container[0][config.scrollOffset] + theStep, scrollDistance);
68      } else {
69        newScrollOffset = Math.min(container[0][config.scrollOffset] + config.step, scrollDistance);
70      }
71      container[0][config.scrollOffset] = newScrollOffset;
72
73      if (newScrollOffset >= scrollDistance) {
74        for (i = 0; i < config.switchItems; i++) {
75          if (config.queue && config.queue.hasChildNodes() && config.queue.getElementsByTagName('li').length > 0) {
76            containerUL.append(config.queue.getElementsByTagName('li')[0]);
77            containerUL.remove(containerUL.children('li:first-child'));
78          } else {
79            containerUL.append(containerUL.children('li:first-child'));
80          }
81        }
82        container[0][config.scrollOffset] = 0;
83        clearInterval(scrollingId);
84        if (config.autoPlay) {
85          nextScrollId = setTimeout(forward, config.delay * 1000);
86        }
87      }
88    };
89    // Backward
90    // 1. If forwarding, then reverse
91    // 2. If stoping, then backward once
92    scrollBackward = function() {
93      if (paused) {
94        return;
95      }
96      var curLi,
97          i,
98          liLen,
99          newScrollOffset,
100          scrollDistance,
101          theStep;
102
103      // init
104      if (container[0][config.scrollOffset] === 0) {
105        liLen = containerUL.children('li').length;
106        for (i = 0; i < config.switchItems; i++) {
107          containerUL.children('li:last-child').insertBefore(containerUL.children('li:first-child'));
108        }
109
110        curLi = container.children('li:first-child');
111        scrollDistance = config.distance !== 'auto' ?
112            config.distance :
113            config.direction === 'vertical' ? curLi.height() : curLi.width();
114        container[0][config.scrollOffset] = scrollDistance;
115      }
116
117      // new offset
118      if (!config.linear) {
119        theStep = Math.max(3, parseInt(container[0][config.scrollOffset] * 0.3, 10));
120        newScrollOffset = Math.max(container[0][config.scrollOffset] - theStep, 0);
121      } else {
122        newScrollOffset = Math.max(container[0][config.scrollOffset] - config.step, 0);
123      }
124      container[0][config.scrollOffset] = newScrollOffset;
125
126      if (newScrollOffset === 0) {
127        clearInterval(scrollingId);
128        if (config.autoPlay) {
129          nextScrollId = setTimeout(forward, config.delay * 1000);
130        }
131      }
132    };
133
134    forward = function() {
135      clearInterval(scrollingId);
136      scrollingId = setInterval(scrollForward, config.speed);
137    };
138
139    backward = function() {
140      clearInterval(scrollingId);
141      scrollingId = setInterval(scrollBackward, config.speed);
142    };
143
144    resetClock = function(delay) {
145      config.delay = delay || config.delay;
146      clearTimeout(nextScrollId);
147      if (config.autoPlay) {
148        nextScrollId = setTimeout(forward, config.delay * 1000);
149      }
150    };
151
152    if (config.autoPlay) {
153      nextScrollId = setTimeout(forward, config.startDelay * 1000);
154    }
155    // bind events for container
156    container.bind('resetClock', function(delay) { resetClock(delay); });
157    container.bind('forward', function() { clearTimeout(nextScrollId); forward(); });
158    container.bind('backward', function() { clearTimeout(nextScrollId); backward(); });
159    container.bind('speedUp', function(speed) {
160      if (typeof speed === 'undefined') {
161        speed = Math.max(1, parseInt(config.speed / 2, 10));
162      }
163      config.speed = speed;
164    });
165    container.bind('speedDown', function(speed) {
166      if (typeof speed === 'undefined') {
167        speed = config.speed * 2;
168      }
169      config.speed = speed;
170    });
171  });
172};
173}(jQuery));

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.