Skip to content

Commit a96239b

Browse files
committed
Update script
1 parent cd7a8f4 commit a96239b

File tree

3 files changed

+335
-365
lines changed

3 files changed

+335
-365
lines changed

dist/introscroll.js

Lines changed: 151 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -1,183 +1,160 @@
1-
(function (global, factory) {
2-
if (typeof define === "function" && define.amd) {
3-
define(["exports"], factory);
4-
} else if (typeof exports !== "undefined") {
5-
factory(exports);
6-
} else {
7-
var mod = {
8-
exports: {}
9-
};
10-
factory(mod.exports);
11-
global.introscroll = mod.exports;
1+
"use strict";
2+
3+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4+
5+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
6+
7+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
8+
9+
var IntroScroll = /*#__PURE__*/function () {
10+
function IntroScroll() {
11+
var settings = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
12+
13+
_classCallCheck(this, IntroScroll);
14+
15+
this.settings = Object.assign({}, {
16+
element: '#intro',
17+
wrapper: '#wrapper',
18+
container: '#container',
19+
trigger: '#intro__link',
20+
scrollClass: 'is-scrolled',
21+
duration: 1500,
22+
afterScroll: null
23+
}, settings);
24+
this.win = window;
25+
this.doc = document;
26+
this.element = this.getElement(this.settings.element);
27+
this.wrapper = this.getElement(this.settings.wrapper);
28+
this.container = this.getElement(this.settings.container);
29+
this.trigger = this.getElement(this.settings.trigger);
30+
this.scrollClass = this.settings.scrollClass;
31+
this.duration = this.settings.duration;
32+
this.afterScroll = this.settings.afterScroll;
33+
this.isScrolling = false;
34+
this.init();
1235
}
13-
})(this, function (_exports) {
14-
"use strict";
15-
16-
Object.defineProperty(_exports, "__esModule", {
17-
value: true
18-
});
19-
_exports.default = void 0;
20-
21-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
22-
23-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
24-
25-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
26-
27-
var IntroScroll =
28-
/*#__PURE__*/
29-
function () {
30-
function IntroScroll() {
31-
var settings = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
32-
33-
_classCallCheck(this, IntroScroll);
34-
35-
this.settings = Object.assign({}, {
36-
element: '#intro',
37-
wrapper: '#wrapper',
38-
container: '#container',
39-
trigger: '#intro__link',
40-
scrollClass: 'is-scrolled',
41-
duration: 1500,
42-
afterScroll: null
43-
}, settings);
44-
this.win = window;
45-
this.doc = document;
46-
this.element = this.getElement(this.settings.element);
47-
this.wrapper = this.getElement(this.settings.wrapper);
48-
this.container = this.getElement(this.settings.container);
49-
this.trigger = this.getElement(this.settings.trigger);
50-
this.scrollClass = this.settings.scrollClass;
51-
this.duration = this.settings.duration;
52-
this.afterScroll = this.settings.afterScroll;
53-
this.isScrolling = false;
54-
this.init();
36+
37+
_createClass(IntroScroll, [{
38+
key: "init",
39+
value: function init() {
40+
this.bind();
41+
}
42+
}, {
43+
key: "getElement",
44+
value: function getElement(selector) {
45+
return this.doc.querySelector(selector);
5546
}
47+
}, {
48+
key: "swipe",
49+
value: function swipe(element) {
50+
var touchstartX = 0;
51+
var touchstartY = 0;
52+
var touchendX = 0;
53+
var touchendY = 0;
54+
var onSwipeUp = new Event('onswipeup');
55+
var onSwipeRight = new Event('onswiperight');
56+
var onSwipeDown = new Event('onswipedown');
57+
var onSwipeLeft = new Event('onswipeleft');
58+
var onTap = new Event('tap');
59+
element.addEventListener('touchstart', function (event) {
60+
touchstartX = event.changedTouches[0].screenX;
61+
touchstartY = event.changedTouches[0].screenY;
62+
}, false);
63+
element.addEventListener('touchend', function (event) {
64+
touchendX = event.changedTouches[0].screenX;
65+
touchendY = event.changedTouches[0].screenY;
66+
handleTouch();
67+
}, false);
68+
69+
var handleTouch = function handleTouch() {
70+
if (touchendX < touchstartX) {
71+
element.dispatchEvent(onSwipeLeft);
72+
}
5673

57-
_createClass(IntroScroll, [{
58-
key: "init",
59-
value: function init() {
60-
this.bind();
61-
}
62-
}, {
63-
key: "getElement",
64-
value: function getElement(selector) {
65-
return this.doc.querySelector(selector);
66-
}
67-
}, {
68-
key: "swipe",
69-
value: function swipe(element) {
70-
var touchstartX = 0;
71-
var touchstartY = 0;
72-
var touchendX = 0;
73-
var touchendY = 0;
74-
var onSwipeUp = new Event('onswipeup');
75-
var onSwipeRight = new Event('onswiperight');
76-
var onSwipeDown = new Event('onswipedown');
77-
var onSwipeLeft = new Event('onswipeleft');
78-
var onTap = new Event('tap');
79-
element.addEventListener('touchstart', function (event) {
80-
touchstartX = event.changedTouches[0].screenX;
81-
touchstartY = event.changedTouches[0].screenY;
82-
}, false);
83-
element.addEventListener('touchend', function (event) {
84-
touchendX = event.changedTouches[0].screenX;
85-
touchendY = event.changedTouches[0].screenY;
86-
handleTouch();
87-
}, false);
88-
89-
var handleTouch = function handleTouch() {
90-
if (touchendX < touchstartX) {
91-
element.dispatchEvent(onSwipeLeft);
92-
}
93-
94-
if (touchendX > touchstartX) {
95-
element.dispatchEvent(onSwipeRight);
96-
}
97-
98-
if (touchendY < touchstartY) {
99-
element.dispatchEvent(onSwipeUp);
100-
}
101-
102-
if (touchendY > touchstartY) {
103-
element.dispatchEvent(onSwipeDown);
104-
}
105-
106-
if (touchendY === touchstartY) {
107-
element.dispatchEvent(onTap);
108-
}
109-
};
110-
}
111-
}, {
112-
key: "bind",
113-
value: function bind() {
114-
var _this = this;
115-
116-
var win = this.win;
117-
var trigger = this.trigger;
118-
var element = this.element;
119-
var wrapper = this.wrapper;
120-
var container = this.container;
121-
this.swipe(element);
122-
this.swipe(wrapper);
123-
element.addEventListener('mousewheel', function (event) {
124-
if (event.deltaY > 0) {
125-
_this.enableScroll();
126-
}
127-
}, false);
128-
element.addEventListener('onswipeup', function (event) {
74+
if (touchendX > touchstartX) {
75+
element.dispatchEvent(onSwipeRight);
76+
}
77+
78+
if (touchendY < touchstartY) {
79+
element.dispatchEvent(onSwipeUp);
80+
}
81+
82+
if (touchendY > touchstartY) {
83+
element.dispatchEvent(onSwipeDown);
84+
}
85+
86+
if (touchendY === touchstartY) {
87+
element.dispatchEvent(onTap);
88+
}
89+
};
90+
}
91+
}, {
92+
key: "bind",
93+
value: function bind() {
94+
var _this = this;
95+
96+
var win = this.win;
97+
var trigger = this.trigger;
98+
var element = this.element;
99+
var wrapper = this.wrapper;
100+
var container = this.container;
101+
this.swipe(element);
102+
this.swipe(wrapper);
103+
element.addEventListener('mousewheel', function (event) {
104+
if (event.deltaY > 0) {
129105
_this.enableScroll();
130-
}, false);
131-
wrapper.addEventListener('onswipedown', function (event) {
132-
if (_this.win.pageYOffset <= 0) {
133-
_this.disableScroll();
134-
}
135-
}, false);
136-
container.addEventListener('mousewheel', function (event) {
137-
if (event.deltaY < 0 && _this.win.pageYOffset <= 0) {
138-
_this.disableScroll();
139-
}
140-
}, false);
141-
win.addEventListener('mousewheel', function (event) {
142-
if (win.pageYOffset <= 0 && wrapper.classList.contains(_this.scrollClass) && event.deltaY < 0) {
143-
_this.disableScroll();
144-
}
145-
}, false);
146-
trigger.addEventListener('click', function (event) {
147-
event.preventDefault();
148-
149-
if (!wrapper.classList.contains(_this.scrollClass) || win.pageYOffset > 1) {
150-
_this.enableScroll();
151-
}
152-
}, false);
153-
}
154-
}, {
155-
key: "enableScroll",
156-
value: function enableScroll() {
157-
var _this2 = this;
158-
159-
this.wrapper.classList.add(this.scrollClass);
160-
this.isScrolling = true;
161-
setTimeout(function () {
162-
_this2.doc.body.style.overflow = 'visible';
163-
_this2.isScrolling = false;
164-
typeof _this2.afterScroll === 'function' && _this2.afterScroll(_this2);
165-
}, this.duration);
166-
}
167-
}, {
168-
key: "disableScroll",
169-
value: function disableScroll() {
170-
if (this.isScrolling) {
171-
return;
172106
}
107+
}, false);
108+
element.addEventListener('onswipeup', function (event) {
109+
_this.enableScroll();
110+
}, false);
111+
wrapper.addEventListener('onswipedown', function (event) {
112+
if (_this.win.pageYOffset <= 0) {
113+
_this.disableScroll();
114+
}
115+
}, false);
116+
container.addEventListener('mousewheel', function (event) {
117+
if (event.deltaY < 0 && _this.win.pageYOffset <= 0) {
118+
_this.disableScroll();
119+
}
120+
}, false);
121+
win.addEventListener('mousewheel', function (event) {
122+
if (win.pageYOffset <= 0 && wrapper.classList.contains(_this.scrollClass) && event.deltaY < 0) {
123+
_this.disableScroll();
124+
}
125+
}, false);
126+
trigger.addEventListener('click', function (event) {
127+
event.preventDefault();
173128

174-
this.wrapper.classList.remove(this.scrollClass);
175-
this.doc.body.style.overflow = 'hidden';
129+
if (!wrapper.classList.contains(_this.scrollClass) || win.pageYOffset > 1) {
130+
_this.enableScroll();
131+
}
132+
}, false);
133+
}
134+
}, {
135+
key: "enableScroll",
136+
value: function enableScroll() {
137+
var _this2 = this;
138+
139+
this.wrapper.classList.add(this.scrollClass);
140+
this.isScrolling = true;
141+
setTimeout(function () {
142+
_this2.doc.body.style.overflow = 'visible';
143+
_this2.isScrolling = false;
144+
typeof _this2.afterScroll === 'function' && _this2.afterScroll(_this2);
145+
}, this.duration);
146+
}
147+
}, {
148+
key: "disableScroll",
149+
value: function disableScroll() {
150+
if (this.isScrolling) {
151+
return;
176152
}
177-
}]);
178153

179-
return IntroScroll;
180-
}();
154+
this.wrapper.classList.remove(this.scrollClass);
155+
this.doc.body.style.overflow = 'hidden';
156+
}
157+
}]);
181158

182-
_exports.default = IntroScroll;
183-
});
159+
return IntroScroll;
160+
}();

dist/introscroll.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)