Skip to content

Commit b82e62e

Browse files
committed
adjust callback data-name logic
1 parent 2477266 commit b82e62e

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/js-scroll-effect-module.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,14 @@ export default class SCROLL_EFFECT_MODULE {
288288
_item.count++;
289289
if (this.config.classNameInview) DOM.addClass(_item.el, this.config.classNameInview);
290290
// Inコールバック関数の呼び出し
291-
this.callCallback(this.config.on.In, _item, _item.index, _item.dataset.scrollName);
291+
this.callCallback(this.config.on.In, _item, _item.index, _item.dataset[this.getDatasetKey(this.config.targetDataName)]);
292292
}
293293
} else {
294294
// activeでない場合の処理
295-
if (this.config.displayReverse && DOM.hasClass(_item.el, this.config.classNameInview)) {
295+
if (this.config.reverse && DOM.hasClass(_item.el, this.config.classNameInview)) {
296296
DOM.removeClass(_item.el, this.config.classNameInview);
297297
// Outコールバック関数の呼び出し
298-
this.callCallback(this.config.on.Out, _item, _item.index, _item.dataset.scrollName);
298+
this.callCallback(this.config.on.Out, _item, _item.index, _item.dataset[this.getDatasetKey(this.config.targetDataName)]);
299299
}
300300
}
301301

@@ -307,7 +307,7 @@ export default class SCROLL_EFFECT_MODULE {
307307
let _item_fix = _type === 'down' ? _item : _item_pre;
308308

309309
// Changeコールバック関数の呼び出し
310-
this.callCallback(this.config.on.Change, _item_fix, _item_fix.index, _item_fix.dataset.scrollName);
310+
this.callCallback(this.config.on.Change, _item_fix, _item_fix.index, _item_fix.dataset[this.getDatasetKey(this.config.targetDataName)]);
311311
}
312312
}
313313
}
@@ -319,4 +319,15 @@ export default class SCROLL_EFFECT_MODULE {
319319
}
320320
}
321321

322+
getDatasetKey(_str){
323+
function replacer(_match, _result) {
324+
return _result.toUpperCase();
325+
}
326+
327+
const datasetKey = _str
328+
.replace(/\[data-|\]/g, '')
329+
.replace(/-(.?)/g, replacer);
330+
331+
return datasetKey;
332+
}
322333
}

0 commit comments

Comments
 (0)