PageSourceSearch

https://www.tensinkai.or.jp/assets/js/luxy.js

js tensinkai.or.jp collected 2026-10-04 04:21:11 UTC 6,565 bytes, 212 lines download raw bytes

vendor: 5,307 bytes, lines 1-168
1/**
2 * Written by Mineo Okuda on 01/03/18.
3 *
4 * Mineo Okuda - development + design
5 * https://willstyle.co.jp
6 * https://github.com/min30327
7 *
8 * MIT license.
9 */
10
11(function(root, factory) {
12	'use strict';
13
14	if (typeof define === 'function' && define.amd) {
15		// AMD. Register as an anonymous module.
16		define([], factory);
17	}
18	else if (typeof exports === 'object') {
19		// COMMONJS
20		module.exports = factory();
21	}
22	else {
23		// BROWSER
24		root.luxy = factory();
25	}
26}(this, function() {
27
28	'use strict';
29	
30		var defaults = {
31			wrapper: '#luxy',
32			targets : '.luxy-el',
33			wrapperSpeed: 0.08,
34			targetSpeed: 0.02,
35			targetPercentage: 0.1
36		};
37
38 		var requestAnimationFrame = 
39			window.requestAnimationFrame || window.mozRequestAnimationFrame ||
40			window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
41			window.requestAnimationFrame = requestAnimationFrame;
42		var cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame;
43
44		/**
45		 * Merge two or more objects. Returns a new object.
46		 * @param {Object}   objects  The objects to merge together
47		 * @returns {Object}          Merged values of defaults and options
48		 */
49		var extend = function () {
50
51			// Variables
52			var extended = {};
53			var deep = false;
54			var i = 0;
55			var length = arguments.length;
56
57			// Merge the object into the extended object
58			var merge = function (obj) {
59				for (var prop in obj) {
60					if (obj.hasOwnProperty(prop)) {
61						extended[prop] = obj[prop];
62					}
63				}
64			};
65
66			// Loop through each object and conduct a merge
67			for ( ; i < length; i++ ) {
68				var obj = arguments[i];
69				merge(obj);
70			}
71
72			return extended;
73
74		};
75
76		var Luxy = function(){
77			this.Targets = [];
78			this.TargetsLength = 0;
79			this.wrapper = '';
80			this.windowHeight = 0;
81			this.wapperOffset = 0;
82		};
83		Luxy.prototype = {
84			isAnimate: false,
85			isResize : false,
86			scrollId: "",
87			resizeId: "",
88			init : function(options){
89				this.settings = extend(defaults, options || {});
90				this.wrapper = document.querySelector(this.settings.wrapper);
91
92				if(this.wrapper==="undefined"){
93					return false;
94				}
95				this.targets = document.querySelectorAll(this.settings.targets);
96				document.body.style.height = this.wrapper.clientHeight + 'px';
97
98				this.windowHeight = window.clientHeight;
99				this.attachEvent();
100				this.apply(this.targets,this.wrapper);
101				this.animate();
102				this.resize();
103			},
104			apply : function(targets,wrapper){
105				this.wrapperInit();
106				
107				this.targetsLength = targets.length;
108				for (var i = 0; i < this.targetsLength; i++) {
109					var attr = {
110						offset : targets[i].getAttribute('data-offset'),
111						speedX : targets[i].getAttribute('data-speed-x'),
112						speedY : targets[i].getAttribute('data-speed-Y'),
113						percentage : targets[i].getAttribute('data-percentage'),
114						horizontal : targets[i].getAttribute('data-horizontal')
115					};
116					this.targetsInit(targets[i],attr);
117				}
118			},
119			wrapperInit: function(){
120				this.wrapper.style.width = '100%';
121				this.wrapper.style.position = 'fixed';
122			},
123			targetsInit: function(elm,attr){
124				
125				this.Targets.push({
126					elm : elm,
127					offset : attr.offset ? attr.offset : 0,
128					horizontal : attr.horizontal ? attr.horizontal : 0,
129					top : 0,
130					left : 0,
131					speedX : attr.speedX ? attr.speedX : 1,
132					speedY : attr.speedY ? attr.speedY : 1,
133					percentage :attr.percentage ? attr.percentage : 0
134				});
135			},
136			scroll : function(){
137				var scrollTopTmp = document.documentElement.scrollTop || document.body.scrollTop;
138				this.scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
139				var offsetBottom = this.scrollTop + this.windowHeight;
140				this.wrapperUpdate(this.scrollTop);
141				for (var i = 0; i < this.Targets.length; i++) {
142					this.targetsUpdate(this.Targets[i]);
143				}
144			},
145			animate : function(){
146				this.scroll();
147				this.scrollId = requestAnimationFrame(this.animate.bind(this));
148			},
149			wrapperUpdate : function(){
150				
151				this.wapperOffset += (this.scrollTop - this.wapperOffset) * this.settings.wrapperSpeed;
152				this.wrapper.style.transform = 'translate3d(' + 0 + ',' +  Math.round(-this.wapperOffset* 100) / 100 + 'px ,' + 0 + ')';
153			},
154			targetsUpdate : function(target){
155				target.top += (this.scrollTop * Number(this.settings.targetSpeed) * Number(target.speedY) - target.top) * this.settings.targetPercentage;
156				target.left += (this.scrollTop * Number(this.settings.targetSpeed) * Number(target.speedX) - target.left) * this.settings.targetPercentage;
157				var targetOffsetTop = ( parseInt(target.percentage) - target.top - parseInt(target.offset) );
158				var offsetY = Math.round(targetOffsetTop * -100) / 100;
159				var offsetX = 0;
160				if(target.horizontal){
161					var targetOffsetLeft = ( parseInt(target.percentage) - target.left - parseInt(target.offset) );
162					offsetX = Math.round(targetOffsetLeft * -100) / 100;
163				}
164				target.elm.style.transform = 'translate3d(' + offsetX + 'px ,' + offsetY + 'px ,' + 0 +')';
165			},
166			resize: function(){
167				var self = this;
168				self.windowHeight = (window.innerHeight || document.documentElement.clientHeight || 0
168);
169				if( parseInt(self.wrapper.clientHeight) != parseInt(document.body.style.height)){
170					// document.body.style.height = self.wrapper.clientHeight + 'px';
171				}
172				self.resizeId = requestAnimationFrame(self.resize.bind(self));
173			},
174			attachEvent : function(){
175				var self = this;
176				window.addEventListener('resize',function(){
177					if(!self.isResize){
178						cancelAnimationFrame(self.resizeId);
179						cancelAnimationFrame(self.scrollId);
180						self.isResize = true;
181						setTimeout(function(){
182							self.isResize = false;
183							self.resizeId = requestAnimationFrame(self.resize.bind(self));
184							self.scrollId = requestAnimationFrame(self.animate.bind(self));
185						},200);
186					}
187				});
188				
189			},
190			cancel: function() {
191				cancelAnimationFrame(this.resizeId);
192				cancelAnimationFrame(this.scrollId);
193				this.wrapper.removeAttribute('style');
194				for (var i = 0; i < this.Targets.length; i++) {
195					this.Targets[i].elm.removeAttribute('style');
196				}
197				this.wrapper = '';
198				this.Targets = [];
199				this.windowHeight = 0;
200				this.wapperOffset = 0;
201				this.isResize = false;
202				this.scrollId = "";
203				this.resizeId = "";
204			},
205		};
206
207		
208		var luxy = new Luxy();
209
210		return luxy;
211	})
212);

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.