~(function ($, window, document, undefined) { class Scroll { constructor(eles, opts) { this.$eles = eles; opts = opts || {}; this.defaults = { mode: 'CSS', cssSpeed: 5, jsSpeed: 'normal', }; this.options = $.extend(true, {}, this.defaults, opts); this.options.jsSpeed = this.handleJsSpeed(this.options.jsSpeed); this.init(); } init() { this.handleEve(); } handleJsSpeed(sp) { switch (sp) { case 'slow': return 50; case 'normal': return 30; case 'fast': return 15; } } handleEve() { const _this = this; this.$eles.each(function (i, domEle) { _this.cloneNode(domEle); _this.initValue(domEle); _this.wrapDiv(domEle); _this.createKeyframes(); if (_this.options.mode === 'CSS') { _this.moveByCss(domEle); _this.handleHoverByCss(domEle); } else { _this.moveByJs(domEle); _this.handleHoverByJs(domEle); } }); } cloneNode(ele) { $(ele).children().clone().appendTo($(ele)); } initValue(ele) { $(ele).css({ margin: 0, padding: 0 }); ele.num = 0; const o = $(ele).parents(":hidden").eq($(ele).parents(":hidden").length - 1); o.css({ display: 'block' }); // ele.h = parseInt($(ele).outerHeight(true) / 2); // To prevent the father setting display: flex; from affecting the height of the child element let sum = 0; $(ele).children().each(function (i, item) { sum += $(item).outerHeight(true); }); ele.h = parseInt(sum / 2); o.css({ display: 'none' }); } wrapDiv(ele) { $(ele).wrap($(`