PageSourceSearch

https://matsumoto.ed.jp/wp-content/themes/insp_para/js/parallax.js?ver=1561346594

js matsumoto.ed.jp collected 2026-10-05 09:39:46 UTC 10,790 bytes, 358 lines download raw bytes

vendor: 9,064 bytes, lines 1-279
1/*!
2 * parallax.js v1.3.1 (http://pixelcog.github.io/parallax.js/)
3 * @copyright 2015 PixelCog, Inc.
4 * @license MIT (https://github.com/pixelcog/parallax.js/blob/master/LICENSE)
5 */
6
7;(function ( $, window, document, undefined ) {
8
9  // Polyfill for requestAnimationFrame
10  // via: https://gist.github.com/paulirish/1579671
11
12  (function() {
13    var lastTime = 0;
14    var vendors = ['ms', 'moz', 'webkit', 'o'];
15    for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
16      window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
17      window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
18                                 || window[vendors[x]+'CancelRequestAnimationFrame'];
19    }
20
21    if (!window.requestAnimationFrame)
22      window.requestAnimationFrame = function(callback) {
23        var currTime = new Date().getTime();
24        var timeToCall = Math.max(0, 16 - (currTime - lastTime));
25        var id = window.setTimeout(function() { callback(currTime + timeToCall); },
26          timeToCall);
27        lastTime = currTime + timeToCall;
28        return id;
29      };
30
31    if (!window.cancelAnimationFrame)
32      window.cancelAnimationFrame = function(id) {
33        clearTimeout(id);
34      };
35  }());
36
37
38  // Parallax Constructor
39
40  function Parallax(element, options) {
41    var self = this;
42
43    if (typeof options == 'object') {
44      delete options.refresh;
45      delete options.render;
46      $.extend(this, options);
47    }
48
49    this.$element = $(element);
50
51    if (!this.imageSrc && this.$element.is('img')) {
52      this.imageSrc = this.$element.attr('src');
53    }
54
55    var positions = (this.position + '').toLowerCase().match(/\S+/g) || [];
56
57    if (positions.length < 1) {
58      positions.push('center');
59    }
60    if (positions.length == 1) {
61      positions.push(positions[0]);
62    }
63
64    if (positions[0] == 'top' || positions[0] == 'bottom' || positions[1] == 'left' || positions[1] == 'right') {
65      positions = [positions[1], positions[0]];
66    }
67
68    if (this.positionX != undefined) positions[0] = this.positionX.toLowerCase();
69    if (this.positionY != undefined) positions[1] = this.positionY.toLowerCase();
70
71    self.positionX = positions[0];
72    self.positionY = positions[1];
73
74    if (this.positionX != 'left' && this.positionX != 'right') {
75      if (isNaN(parseInt(this.positionX))) {
76        this.positionX = 'center';
77      } else {
78        this.positionX = parseInt(this.positionX);
79      }
80    }
81
82    if (this.positionY != 'top' && this.positionY != 'bottom') {
83      if (isNaN(parseInt(this.positionY))) {
84        this.positionY = 'center';
85      } else {
86        this.positionY = parseInt(this.positionY);
87      }
88    }
89
90    this.position =
91      this.positionX + (isNaN(this.positionX)? '' : 'px') + ' ' +
92      this.positionY + (isNaN(this.positionY)? '' : 'px');
93
94    if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
95      if (this.iosFix && !this.$element.is('img')) {
96        this.$element.css({
97          backgroundImage: 'url(' + this.imageSrc + ')',
98          backgroundSize: 'cover',
99          backgroundPosition: this.position
100        });
101      }
102      return this;
103    }
104
105    if (navigator.userAgent.match(/(Android)/)) {
106      if (this.androidFix && !this.$element.is('img')) {
107        this.$element.css({
108          backgroundImage: 'url(' + this.imageSrc + ')',
109          backgroundSize: 'cover',
110          backgroundPosition: this.position
111        });
112      }
113      return this;
114    }
115
116    this.$mirror = $('<div />').prependTo('body');
117    this.$slider = $('<img />').prependTo(this.$mirror);
118
119    this.$mirror.addClass('parallax-mirror').css({
120      visibility: 'hidden',
121      zIndex: this.zIndex,
122      position: 'fixed',
123      top: 0,
124      left: 0,
125      overflow: 'hidden'
126    });
127
128    this.$slider.addClass('parallax-slider').one('load', function() {
129      if (!self.naturalHeight || !self.naturalWidth) {
130        self.naturalHeight = this.naturalHeight || this.height || 1;
131        self.naturalWidth  = this.naturalWidth  || this.width  || 1;
132      }
133      self.aspectRatio = self.naturalWidth / self.naturalHeight;
134
135      Parallax.isSetup || Parallax.setup();
136      Parallax.sliders.push(self);
137      Parallax.isFresh = false;
138      Parallax.requestRender();
139    });
140
141    this.$slider[0].src = this.imageSrc;
142
143    if (this.naturalHeight && this.naturalWidth || this.$slider[0].complete) {
144      this.$slider.trigger('load');
145    }
146
147  };
148
149
150  // Parallax Instance Methods
151
152  $.extend(Parallax.prototype, {
153    speed:    0.2,
154    bleed:    0,
155    zIndex:   -100,
156    iosFix:   true,
157    androidFix: true,
158    position: 'center',
159    overScrollFix: false,
160
161    refresh: function() {
162      this.boxWidth        = this.$element.outerWidth();
163      this.boxHeight       = this.$element.outerHeight() + this.bleed * 2;
164      this.boxOffsetTop    = this.$element.offset().top - this.bleed;
165      this.boxOffsetLeft   = this.$element.offset().left;
166      this.boxOffsetBottom = this.boxOffsetTop + this.boxHeight;
167
168      var winHeight = Parallax.winHeight;
169      var docHeight = Parallax.docHeight;
170      var maxOffset = Math.min(this.boxOffsetTop, docHeight - winHeight);
171      var minOffset = Math.max(this.boxOffsetTop + this.boxHeight - winHeight, 0);
172      var imageHeightMin = this.boxHeight + (maxOffset - minOffset) * (1 - this.speed) | 0;
173      var imageOffsetMin = (this.boxOffsetTop - maxOffset) * (1 - this.speed) | 0;
174
175      if (imageHeightMin * this.aspectRatio >= this.boxWidth) {
176        this.imageWidth    = imageHeightMin * this.aspectRatio | 0;
177        this.imageHeight   = imageHeightMin;
178        this.offsetBaseTop = imageOffsetMin;
179
180        var margin = this.imageWidth - this.boxWidth;
181
182        if (this.positionX == 'left') {
183          this.offsetLeft = 0;
184        } else if (this.positionX == 'right') {
185          this.offsetLeft = - margin;
186        } else if (!isNaN(this.positionX)) {
187          this.offsetLeft = Math.max(this.positionX, - margin);
188        } else {
189          this.offsetLeft = - margin / 2 | 0;
190        }
191      } else {
192        this.imageWidth    = this.boxWidth;
193        this.imageHeight   = this.boxWidth / this.aspectRatio | 0;
194        this.offsetLeft    = 0;
195
196        var margin = this.imageHeight - imageHeightMin;
197
198        if (this.positionY == 'top') {
199          this.offsetBaseTop = imageOffsetMin;
200        } else if (this.positionY == 'bottom') {
201          this.offsetBaseTop = imageOffsetMin - margin;
202        } else if (!isNaN(this.positionY)) {
203          this.offsetBaseTop = imageOffsetMin + Math.max(this.positionY, - margin);
204        } else {
205          this.offsetBaseTop = imageOffsetMin - margin / 2 | 0;
206        }
207      }
208    },
209
210    render: function() {
211      var scrollTop    = Parallax.scrollTop;
212      var scrollLeft   = Parallax.scrollLeft;
213      var overScroll   = this.overScrollFix ? Parallax.overScroll : 0;
214      var scrollBottom = scrollTop + Parallax.winHeight;
215
216      if (this.boxOffsetBottom > scrollTop && this.boxOffsetTop < scrollBottom) {
217        this.visibility = 'visible';
218      } else {
219        this.visibility = 'hidden';
220      }
221      this.mirrorTop = this.boxOffsetTop  - scrollTop;
222      this.mirrorLeft = this.boxOffsetLeft - scrollLeft;
223      this.offsetTop = this.offsetBaseTop - this.mirrorTop * (1 - this.speed);
224
225      this.$mirror.css({
226        transform: 'translate3d(0px, 0px, 0px)',
227        visibility: this.visibility,
228        top: this.mirrorTop - overScroll,
229        left: this.mirrorLeft,
230        height: this.boxHeight,
231        width: this.boxWidth
232      });
233
234      this.$slider.css({
235        transform: 'translate3d(0px, 0px, 0px)',
236        position: 'absolute',
237        top: this.offsetTop,
238        left: this.offsetLeft,
239        height: this.imageHeight,
240        width: this.imageWidth,
241        maxWidth: 'none'
242      });
243    }
244  });
245
246
247  // Parallax Static Methods
248
249  $.extend(Parallax, {
250    scrollTop:    0,
251    scrollLeft:   0,
252    winHeight:    0,
253    winWidth:     0,
254    docHeight:    1 << 30,
255    docWidth:     1 << 30,
256    sliders:      [],
257    isReady:      false,
258    isFresh:      false,
259    isBusy:       false,
260
261    setup: function() {
262      if (this.isReady) return;
263
264      var $doc = $(document), $win = $(window);
265
266      $win.on('scroll.px.parallax load.px.parallax', function() {
267          var scrollTopMax  = Parallax.docHeight - Parallax.winHeight;
268          var scrollLeftMax = Parallax.docWidth  - Parallax.winWidth;
269          Parallax.scrollTop  = Math.max(0, Math.min(scrollTopMax,  $win.scrollTop()));
270          Parallax.scrollLeft = Math.max(0, Math.min(scrollLeftMax, $win.scrollLeft()));
271          Parallax.overScroll = Math.max($win.scrollTop() - scrollTopMax, Math.min($win.scrollTop(), 0));
272          Parallax.requestRender();
273        })
274        .on('resize.px.parallax load.px.parallax', function() {
275          Parallax.winHeight = $win.height();
276          Parallax.winWidth  = $win.width();
277          Parallax.docHeight = $doc.height();
278          Parallax.docWidth  = $doc.width();
279          Parallax.isFresh = false;
280          Parallax.requestRender();
281        });
282
283      this.isReady = true;
284    },
285
286    configure: function(options) {
287      if (typeof options == 'object') {
288        delete options.refresh;
289        delete options.render;
290        $.extend(this.prototype, options);
291      }
292    },
293
294    refresh: function() {
295      $.each(this.sliders, function(){ this.refresh() });
296      this.isFresh = true;
297    },
298
299    render: function() {
300      this.isFresh || this.refresh();
301      $.each(this.sliders, function(){ this.render() });
302    },
303
304    requestRender: function() {
305      var self = this;
306
307      if (!this.isBusy) {
308        this.isBusy = true;
309        window.requestAnimationFrame(function() {
310          self.render();
311          self.isBusy = false;
312        });
313      }
314    }
315  });
316
317
318  // Parallax Plugin Definition
319
320  function Plugin(option) {
321    return this.each(function () {
322      var $this = $(this);
323      var options = typeof option == 'object' && option;
324
325      if (this == window || this == document || $this.is('body')) {
326        Parallax.configure(options);
327      }
328      else if (!$this.data('px.parallax')) {
329        options = $.extend({}, $this.data(), options);
330        $this.data('px.parallax', new Parallax(this, options));
331      }
332      if (typeof option == 'string') {
333        Parallax[option]();
334      }
335    })
336  };
337
338  var old = $.fn.parallax;
339
340  $.fn.parallax             = Plugin;
341  $.fn.parallax.Constructor = Parallax;
342
343
344  // Parallax No Conflict
345
346  $.fn.parallax.noConflict = function () {
347    $.fn.parallax = old;
348    return this;
349  };
350
351
352  // Parallax Data-API
353
354  $(document).on('ready.px.parallax.data-api', function () {
355    $('[data-parallax="scroll"]').parallax();
356  });
357
358}(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.