Giter Site home page Giter Site logo

Comments (9)

lzxb avatar lzxb commented on August 16, 2024

切换选项卡的时候,可以调用一下eachDOM()方法

from lazy-load-img.

79229788 avatar 79229788 commented on August 16, 2024

还是不行哦,我这边用的是Backbone,在渲染的时候,我用JQ添加了图片列表模板后,马上调用该插件,第一屏无法加载,不切换tab时(第一个tab出现时),我用的setTimeout(fn, 0)调用插件,就可以了,。。。。。。。但是切换到其他页时,就又不行了,只能setTimeout(fn, 100)后,就通通可以了。

from lazy-load-img.

lzxb avatar lzxb commented on August 16, 2024

@79229788 能上截图看看么

from lazy-load-img.

lzxb avatar lzxb commented on August 16, 2024

@79229788 目前只箭头了这些事件,会触发检测机制:'DOMContentLoaded', 'load', 'click', 'touchstart', 'touchend', 'haschange', 'online', 'pageshow', 'popstate', 'resize', 'storage', 'mousewheel', 'scroll'

from lazy-load-img.

79229788 avatar 79229788 commented on August 16, 2024

已经知道原因了,jq添加到页面的img列表时,里面的默认图片都还没加载完毕,虽然是本地的图,速度极快,但是在jq添加的下一句就调用你的插件,此时getBoundingClientRect获取的位置应该全都是错误的,就正确无法判断第一屏的图是否在当前可视区。就都没有加载,所以要碰一下才会加载。这个问题可以在插件外面解决,不过你也可以开放一个属性,就是默认第一屏强制加载图片个数,这样我就不需要外部解决了,比如我做的这个页面固定每屏就2个图,有需求的,比如我就可以设置为2,这样问题就解决了。

from lazy-load-img.

79229788 avatar 79229788 commented on August 16, 2024
  我没用过github pull别人的项目,希望能采纳下。 

  我添加了一个属性,和修改了一个方法
   (之前那个遍历你是2个循环,我改成一个了,没必要循环2次哈)
       this.fistLoadCount = 0; //首次加载图片个数


        /**
         * 遍历DOM元素
         */
        this.eachDOM = () => {
            var list = document.querySelectorAll(this.el);
            for (let i = 0; i < list.length; i++) {
                if (this.testMeet(list[i]) === true || i <= this.fistLoadCount - 1) {
                  this.loadImg(list[i]);
                }
            }
        };

from lazy-load-img.

79229788 avatar 79229788 commented on August 16, 2024

对了,每次start()前,你看看有没有必要在start()内部调用下end(),也就是添加事件之前删除原有事件,因为比如在异步添加时,比如tab切换时,每次会清空之前html,那么切换时调用start(),自然绑定的事件也可以清除在添加了

from lazy-load-img.

79229788 avatar 79229788 commented on August 16, 2024

特别奇怪的是。。。。。。。。。
用你的非压缩版电脑端可以跑起来,手机端无法使用懒加载(一个图都不加载)。
而你的压缩版正常,两端都正常运行,难道是2套不一样的代码么,匪夷所思哈。
刚刚的需求我只好在压缩版里面一点一点的揪出来修改了,幸好东西不多。
不过还是希望你那边能考虑下我刚刚的需求哈(异步加载HTML场景太多了,或者用另外一个的方式,就是先判断default图先加载好,在用操作懒加载的事情,都行)~~~

from lazy-load-img.

lzxb avatar lzxb commented on August 16, 2024

@79229788 都是很久以前写的代码了,有时间我再重构一下,最近在忙vue-cnode的开发,基本上很少照顾到这些了

from lazy-load-img.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.