1
0
mirror of https://github.com/locomotivemtl/locomotive-boilerplate.git synced 2026-01-15 00:55:08 +08:00
Files
locomotive-boilerplate/assets/scripts/modules/Scroll.js

42 lines
959 B
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { module } from 'modujs';
import LocomotiveScroll from 'locomotive-scroll';
export default class extends module {
constructor(m) {
super(m);
}
init() {
this.scroll = new LocomotiveScroll({
el: this.el,
smooth: true
});
this.scroll.on('call', (func,way,obj,id) => {
// Using modularJS
this.call(func[0],{way,obj},func[1],func[2]);
});
this.scroll.on('scroll', (args) => {
// console.log(args.scroll);
})
}
toggleLazy(args) {
let src = this.getData('lazy', args.obj.el)
if(src.length) {
if(args.obj.el.tagName == "IMG") {
args.obj.el.src = src
} else {
args.obj.el.style.backgroundImage = `url(${src})`
}
this.setData('lazy', '', args.obj.el)
}
}
destroy() {
this.scroll.destroy();
}
}