Skip to content

Commit 97ffb1d

Browse files
committed
adjust
1 parent e22eaf9 commit 97ffb1d

File tree

1 file changed

+43
-14
lines changed

1 file changed

+43
-14
lines changed

src/js-scroll-effect-module.js

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default class SCROLL_EFFECT_MODULE {
2727
throttleInterval : 3,
2828

2929
autoStart : true,
30+
autoStartType : 'ready', // ready, load, scroll
3031

3132
on: {
3233
Scroll : null,
@@ -42,6 +43,9 @@ export default class SCROLL_EFFECT_MODULE {
4243
...options
4344
};
4445

46+
this.timer = null;
47+
this.timerScroll = null;
48+
4549
// adjust ratio value.
4650
if( !this.config.displayRatioReverse ) {
4751
this.config.displayRatioReverse = this.config.displayRatio;
@@ -84,27 +88,34 @@ export default class SCROLL_EFFECT_MODULE {
8488
}
8589

8690
_BindEvent(){
87-
let _that = this;
91+
if(this.timer) clearTimeout(this.timer);
8892

8993
// for Resize-Event
9094
window.addEventListener('resize', () => {
91-
this.Update();
95+
this.Start();
9296
});
9397

94-
// for Load-Event
95-
window.addEventListener('load', () => {
96-
this.Update();
97-
if(this.timer){
98-
clearTimeout(this.timer);
98+
if(this.config.autoStartType === 'ready'){
99+
this.timer = setTimeout(()=>{
100+
this.Start();
101+
this._BindEventScroll();
102+
}, this.config.firstDelay);
103+
} else if(this.config.autoStartType === 'load'){
104+
// for Load-Event
105+
window.addEventListener('load', () => {
99106
this.timer = setTimeout(()=>{
100-
this._StoreElementStateAtPosList();
107+
this.Start();
108+
this._BindEventScroll();
101109
}, this.config.firstDelay);
102-
}
103-
});
110+
});
111+
} else if(this.config.autoStartType === 'scroll'){
112+
this._BindEventScroll();
113+
}
114+
}
115+
_BindEventScroll(){
116+
let _that = this;
104117

105-
this.timer = setTimeout(()=>{
106-
this._StoreElementStateAtPosList();
107-
}, this.config.firstDelay);
118+
if(this.timerScroll) clearTimeout(this.timerScroll);
108119

109120
// for Scroll-Event
110121
function throttle(fn, wait) {
@@ -116,9 +127,27 @@ export default class SCROLL_EFFECT_MODULE {
116127
}
117128
};
118129
}
130+
131+
// スクロールの間引き処理
119132
window.addEventListener('scroll', throttle(function(){
120133
_that._StoreElementStateAtPosList();
121-
}, this.config.throttleInterval), {passive: true});
134+
}, _that.config.throttleInterval), {passive: true});
135+
136+
let _flg = false;
137+
window.addEventListener('scroll', ()=>{
138+
// スクロール開始時に一度だけ実行
139+
if(!_flg)_that._StoreElementStateAtPosList();
140+
141+
_flg = true;
142+
143+
if(this.timerScroll) clearTimeout(this.timerScroll);
144+
145+
// スクロール終了時に実行
146+
_that.timerScroll = setTimeout(()=>{
147+
_flg = false;
148+
_that._StoreElementStateAtPosList();
149+
}, _that.config.throttleInterval);
150+
}, {passive: true});
122151
}
123152

124153
_SetDom(){

0 commit comments

Comments
 (0)