Commit ff9e46a7 by Yutaka Kobayashi

モーダルとフェードインを動くように修正

1 parent ec58005a
...@@ -7,15 +7,16 @@ ...@@ -7,15 +7,16 @@
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/). * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/ */
/******/ (function() { // webpackBootstrap /******/ (function() { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({ /******/ var __webpack_modules__ = ({
/***/ "./src/assets/js/fadeIn.js": /***/ "./src/assets/js/fadeIn.js":
/*!*********************************!*\ /*!*********************************!*\
!*** ./src/assets/js/fadeIn.js ***! !*** ./src/assets/js/fadeIn.js ***!
\*********************************/ \*********************************/
/***/ (function() { /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
eval("throw new Error(\"Module parse failed: Unexpected token (12:8)\\nYou may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders\\n| }\\n| \\n> window.addEventListener(\\n| \\\"scroll\\\",\\n| throttle(300, () => {\");\n\n//# sourceURL=webpack://static-boilerplate/./src/assets/js/fadeIn.js?"); eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"Fade\": function() { return /* binding */ Fade; }\n/* harmony export */ });\n/* harmony import */ var throttle_debounce__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! throttle-debounce */ \"./node_modules/throttle-debounce/esm/index.js\");\n\nclass Fade {\n constructor() {\n this.elements = {\n element: document.getElementsByClassName(\"scrollUp\"),\n scrollY: window.pageYOffset,\n windowHeight: window.innerHeight,\n showTiming: 200,\n };\n\n window.addEventListener(\n \"scroll\",\n (0,throttle_debounce__WEBPACK_IMPORTED_MODULE_0__.throttle)(300, () => {\n window.addEventListener(\"scroll\", () => {\n for (let i = 0; i < this.elements.element.length; i++) {\n let elementClientRect =\n this.elements.element[i].getBoundingClientRect();\n let elementY = this.elements.scrollY + elementClientRect.top;\n if (\n scrollY >\n elementY - this.elements.windowHeight + this.elements.showTiming\n ) {\n this.elements.element[i].classList.add(\"is-show\");\n }\n }\n });\n })\n );\n }\n}\n\n\n//# sourceURL=webpack://static-boilerplate/./src/assets/js/fadeIn.js?");
/***/ }), /***/ }),
...@@ -25,7 +26,6 @@ eval("throw new Error(\"Module parse failed: Unexpected token (12:8)\\nYou may n ...@@ -25,7 +26,6 @@ eval("throw new Error(\"Module parse failed: Unexpected token (12:8)\\nYou may n
\*******************************/ \*******************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _modal_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./modal.js */ \"./src/assets/js/modal.js\");\n/* harmony import */ var _fadeIn_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./fadeIn.js */ \"./src/assets/js/fadeIn.js\");\n\n\n\nclass Home {\n constructor() {\n new _modal_js__WEBPACK_IMPORTED_MODULE_0__.Modal();\n new _fadeIn_js__WEBPACK_IMPORTED_MODULE_1__.Fade();\n }\n}\n\ndocument.addEventListener(\"DOMContentLoaded\", () => {\n new Home();\n});\n\n\n//# sourceURL=webpack://static-boilerplate/./src/assets/js/home.js?"); eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _modal_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./modal.js */ \"./src/assets/js/modal.js\");\n/* harmony import */ var _fadeIn_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./fadeIn.js */ \"./src/assets/js/fadeIn.js\");\n\n\n\nclass Home {\n constructor() {\n new _modal_js__WEBPACK_IMPORTED_MODULE_0__.Modal();\n new _fadeIn_js__WEBPACK_IMPORTED_MODULE_1__.Fade();\n }\n}\n\ndocument.addEventListener(\"DOMContentLoaded\", () => {\n new Home();\n});\n\n\n//# sourceURL=webpack://static-boilerplate/./src/assets/js/home.js?");
/***/ }), /***/ }),
...@@ -36,8 +36,17 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _mod ...@@ -36,8 +36,17 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _mod
\********************************/ \********************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict"; eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"Modal\": function() { return /* binding */ Modal; }\n/* harmony export */ });\nclass Modal {\n constructor() {\n // DOM要素を取得している\n this.elements = {\n body: document.querySelector(\"body\"),\n button: document.querySelectorAll(\".novelList__button\"),\n modalBack: document.querySelector(\".modalBackground\"),\n modal: document.querySelectorAll(\".modal\"),\n closeTrigger: document.querySelectorAll(\".closeButton\"),\n };\n\n // モーダルが開いた時のクラス名\n this.openClassName = \"open\";\n\n // ①モーダルを開く処理を登録\n for (let number = 0; number < this.elements.button.length; number++) {\n this.elements.button[number].addEventListener(\"click\", () => {\n this.open(number);\n });\n }\n\n // ②モーダルを閉じる処理を登録\n for (let i = 0; i < this.elements.closeTrigger.length; i++) {\n this.elements.closeTrigger[i].addEventListener(\"click\", () => {\n this.close();\n });\n }\n }\n\n // ①モーダルを開く処理\n open(index) {\n this.elements.body.classList.add(this.openClassName);\n this.elements.modalBack.classList.add(this.openClassName);\n this.elements.modal[index].classList.add(this.openClassName);\n }\n\n // ②モーダルを閉じる処理\n close() {\n this.elements.body.classList.remove(this.openClassName);\n this.elements.modalBack.classList.remove(this.openClassName);\n for (let i = 0; i < this.elements.modal.length; i++) {\n this.elements.modal[i].classList.remove(this.openClassName);\n }\n }\n}\n\n\n//# sourceURL=webpack://static-boilerplate/./src/assets/js/modal.js?");
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"Modal\": function() { return /* binding */ Modal; }\n/* harmony export */ });\nclass Modal {\n constructor() {\n // DOM要素を取得している\n this.elements = {\n body: document.querySelector(\"body\"),\n button: document.querySelectorAll(\".novelList__button\"),\n modalBack: document.querySelector(\".modalBackground\"),\n modal: document.querySelectorAll(\".modal\"),\n closeTrigger: document.querySelectorAll(\".closeButton\"),\n };\n\n // モーダルが開いた時のクラス名\n this.openClassName = \"open\";\n\n // ①モーダルを開く処理を登録\n for (let i = 0; i < this.elements.button.length; i++) {\n this.elements.button[i].addEventListener(\"click\", () => {\n this.open();\n });\n }\n\n // ②モーダルを閉じる処理を登録\n for (let i = 0; i < this.elements.closeTrigger.length; i++) {\n this.elements.closeTrigger[i].addEventListener(\"click\", () => {\n this.close();\n });\n }\n }\n\n // ①モーダルを開く処理\n open() {\n this.elements.body.classList.add(this.openClassName);\n this.elements.modalBack.classList.add(this.openClassName);\n this.elements.modal[index].classList.add(this.openClassName);\n }\n\n // ②モーダルを閉じる処理\n close() {\n this.elements.body.classList.remove(this.openClassName);\n this.elements.modalBack.classList.remove(this.openClassName);\n for (let i = 0; i < this.elements.modal.length; i++) {\n this.elements.modal[i].classList.remove(this.openClassName);\n }\n }\n}\n\n\n//# sourceURL=webpack://static-boilerplate/./src/assets/js/modal.js?");
/***/ }),
/***/ "./node_modules/throttle-debounce/esm/index.js":
/*!*****************************************************!*\
!*** ./node_modules/throttle-debounce/esm/index.js ***!
\*****************************************************/
/***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"debounce\": function() { return /* binding */ debounce; },\n/* harmony export */ \"throttle\": function() { return /* binding */ throttle; }\n/* harmony export */ });\n/* eslint-disable no-undefined,no-param-reassign,no-shadow */\n\n/**\n * Throttle execution of a function. Especially useful for rate limiting\n * execution of handlers on events like resize and scroll.\n *\n * @param {number} delay - A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher)\n * are most useful.\n * @param {Function} callback - A function to be executed after delay milliseconds. The `this` context and all arguments are passed through,\n * as-is, to `callback` when the throttled-function is executed.\n * @param {object} [options] - An object to configure options.\n * @param {boolean} [options.noTrailing] - Optional, defaults to false. If noTrailing is true, callback will only execute every `delay` milliseconds\n * while the throttled-function is being called. If noTrailing is false or unspecified, callback will be executed\n * one final time after the last throttled-function call. (After the throttled-function has not been called for\n * `delay` milliseconds, the internal counter is reset).\n * @param {boolean} [options.noLeading] - Optional, defaults to false. If noLeading is false, the first throttled-function call will execute callback\n * immediately. If noLeading is true, the first the callback execution will be skipped. It should be noted that\n * callback will never executed if both noLeading = true and noTrailing = true.\n * @param {boolean} [options.debounceMode] - If `debounceMode` is true (at begin), schedule `clear` to execute after `delay` ms. If `debounceMode` is\n * false (at end), schedule `callback` to execute after `delay` ms.\n *\n * @returns {Function} A new, throttled, function.\n */\nfunction throttle (delay, callback, options) {\n var _ref = options || {},\n _ref$noTrailing = _ref.noTrailing,\n noTrailing = _ref$noTrailing === void 0 ? false : _ref$noTrailing,\n _ref$noLeading = _ref.noLeading,\n noLeading = _ref$noLeading === void 0 ? false : _ref$noLeading,\n _ref$debounceMode = _ref.debounceMode,\n debounceMode = _ref$debounceMode === void 0 ? undefined : _ref$debounceMode;\n /*\n * After wrapper has stopped being called, this timeout ensures that\n * `callback` is executed at the proper times in `throttle` and `end`\n * debounce modes.\n */\n\n\n var timeoutID;\n var cancelled = false; // Keep track of the last time `callback` was executed.\n\n var lastExec = 0; // Function to clear existing timeout\n\n function clearExistingTimeout() {\n if (timeoutID) {\n clearTimeout(timeoutID);\n }\n } // Function to cancel next exec\n\n\n function cancel(options) {\n var _ref2 = options || {},\n _ref2$upcomingOnly = _ref2.upcomingOnly,\n upcomingOnly = _ref2$upcomingOnly === void 0 ? false : _ref2$upcomingOnly;\n\n clearExistingTimeout();\n cancelled = !upcomingOnly;\n }\n /*\n * The `wrapper` function encapsulates all of the throttling / debouncing\n * functionality and when executed will limit the rate at which `callback`\n * is executed.\n */\n\n\n function wrapper() {\n for (var _len = arguments.length, arguments_ = new Array(_len), _key = 0; _key < _len; _key++) {\n arguments_[_key] = arguments[_key];\n }\n\n var self = this;\n var elapsed = Date.now() - lastExec;\n\n if (cancelled) {\n return;\n } // Execute `callback` and update the `lastExec` timestamp.\n\n\n function exec() {\n lastExec = Date.now();\n callback.apply(self, arguments_);\n }\n /*\n * If `debounceMode` is true (at begin) this is used to clear the flag\n * to allow future `callback` executions.\n */\n\n\n function clear() {\n timeoutID = undefined;\n }\n\n if (!noLeading && debounceMode && !timeoutID) {\n /*\n * Since `wrapper` is being called for the first time and\n * `debounceMode` is true (at begin), execute `callback`\n * and noLeading != true.\n */\n exec();\n }\n\n clearExistingTimeout();\n\n if (debounceMode === undefined && elapsed > delay) {\n if (noLeading) {\n /*\n * In throttle mode with noLeading, if `delay` time has\n * been exceeded, update `lastExec` and schedule `callback`\n * to execute after `delay` ms.\n */\n lastExec = Date.now();\n\n if (!noTrailing) {\n timeoutID = setTimeout(debounceMode ? clear : exec, delay);\n }\n } else {\n /*\n * In throttle mode without noLeading, if `delay` time has been exceeded, execute\n * `callback`.\n */\n exec();\n }\n } else if (noTrailing !== true) {\n /*\n * In trailing throttle mode, since `delay` time has not been\n * exceeded, schedule `callback` to execute `delay` ms after most\n * recent execution.\n *\n * If `debounceMode` is true (at begin), schedule `clear` to execute\n * after `delay` ms.\n *\n * If `debounceMode` is false (at end), schedule `callback` to\n * execute after `delay` ms.\n */\n timeoutID = setTimeout(debounceMode ? clear : exec, debounceMode === undefined ? delay - elapsed : delay);\n }\n }\n\n wrapper.cancel = cancel; // Return the wrapper function.\n\n return wrapper;\n}\n\n/* eslint-disable no-undefined */\n/**\n * Debounce execution of a function. Debouncing, unlike throttling,\n * guarantees that a function is only executed a single time, either at the\n * very beginning of a series of calls, or at the very end.\n *\n * @param {number} delay - A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.\n * @param {Function} callback - A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,\n * to `callback` when the debounced-function is executed.\n * @param {object} [options] - An object to configure options.\n * @param {boolean} [options.atBegin] - Optional, defaults to false. If atBegin is false or unspecified, callback will only be executed `delay` milliseconds\n * after the last debounced-function call. If atBegin is true, callback will be executed only at the first debounced-function call.\n * (After the throttled-function has not been called for `delay` milliseconds, the internal counter is reset).\n *\n * @returns {Function} A new, debounced function.\n */\n\nfunction debounce (delay, callback, options) {\n var _ref = options || {},\n _ref$atBegin = _ref.atBegin,\n atBegin = _ref$atBegin === void 0 ? false : _ref$atBegin;\n\n return throttle(delay, callback, {\n debounceMode: atBegin !== false\n });\n}\n\n\n//# sourceMappingURL=index.js.map\n\n\n//# sourceURL=webpack://static-boilerplate/./node_modules/throttle-debounce/esm/index.js?");
/***/ }) /***/ })
......
...@@ -7,21 +7,24 @@ export class Fade { ...@@ -7,21 +7,24 @@ export class Fade {
windowHeight: window.innerHeight, windowHeight: window.innerHeight,
showTiming: 200, showTiming: 200,
}; };
}
window.addEventListener( window.addEventListener(
"scroll", "scroll",
throttle(300, () => { throttle(300, () => {
window.addEventListener("scroll", () => { window.addEventListener("scroll", () => {
if (!element) return; for (let i = 0; i < this.elements.element.length; i++) {
for (let i = 0; i < element.length; i++) { let elementClientRect =
let elementClientRect = element[i].getBoundingClientRect(); this.elements.element[i].getBoundingClientRect();
let elementY = scrollY + elementClientRect.top; let elementY = this.elements.scrollY + elementClientRect.top;
if (scrollY > elementY - windowHeight + showTiming) { if (
element[i].classList.add("is-show"); scrollY >
elementY - this.elements.windowHeight + this.elements.showTiming
) {
this.elements.element[i].classList.add("is-show");
} }
} }
}); });
}) })
); );
}
} }
...@@ -13,9 +13,9 @@ export class Modal { ...@@ -13,9 +13,9 @@ export class Modal {
this.openClassName = "open"; this.openClassName = "open";
// ①モーダルを開く処理を登録 // ①モーダルを開く処理を登録
for (let i = 0; i < this.elements.button.length; i++) { for (let number = 0; number < this.elements.button.length; number++) {
this.elements.button[i].addEventListener("click", () => { this.elements.button[number].addEventListener("click", () => {
this.open(); this.open(number);
}); });
} }
...@@ -28,7 +28,7 @@ export class Modal { ...@@ -28,7 +28,7 @@ export class Modal {
} }
// ①モーダルを開く処理 // ①モーダルを開く処理
open() { open(index) {
this.elements.body.classList.add(this.openClassName); this.elements.body.classList.add(this.openClassName);
this.elements.modalBack.classList.add(this.openClassName); this.elements.modalBack.classList.add(this.openClassName);
this.elements.modal[index].classList.add(this.openClassName); this.elements.modal[index].classList.add(this.openClassName);
......
...@@ -16,6 +16,6 @@ document.addEventListener("DOMContentLoaded", () => { ...@@ -16,6 +16,6 @@ document.addEventListener("DOMContentLoaded", () => {
// クラス // クラス
new Second(); new Second();
// 関数 // 関数Ç
second(); second();
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!