Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- grLazyFunc: function(selector, callback) {
- var elem = selector;
- var defaultMargin = '10px';
- let options = {
- rootMargin: defaultMargin
- };
- const imageObserver = new IntersectionObserver((entries, imgObserver) => {
- entries.forEach((entry) => {
- if (entry.isIntersecting) {
- const lazyItem = entry.target // Текущий элемент
- if (callback) {
- callback();
- };
- imgObserver.unobserve(lazyItem);
- }
- })
- }, options);
- if (typeof selector == 'string') {
- const arr = document.querySelectorAll(elem);
- arr.forEach((v) => {
- imageObserver.observe(v);
- });
- } else {
- imageObserver.observe(elem);
- };
- },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement