JQuery plugin for lazy-loading/lazy-evaluation?

前端 未结 3 1549
北海茫月
北海茫月 2021-02-10 16:42

Is there such jQuery plugin?

More specific: I want to use some elegant and easy way to postpone some code execution until it\'s really needed (some event happens). And w

相关标签:
3条回答
  • 2021-02-10 17:12

    http://plugins.jquery.com/project/LazyReady

    Lazy Ready A plugin designed to delay code initialization until specified DOM element(s) is interacted with (hovered/focused).

    0 讨论(0)
  • 2021-02-10 17:26

    Answer to more specific question:

    You don't really need any plugin do you? Just do something along these lines.

    This would trigger the function postponedHeavyFunction() only after the user clicks on the element with id lazyelement and only once.

    function postponedHeavyFunction() {
        // unbind. This guarantees that postponedHeavyFunction will only
        // execute once for the event we bound it to #lazyelement
        $("#lazyelement").unbind('click', postponedHeavyFunction);
        ...
        //do whatever 
        ....
    }
    
    //when event is triggered the function you specify gets run
    $("#lazyelement").bind('click', postponedHeavyFunction);
    

    Check http://jsbin.com/agora/ for a dead-stupid demonstration.


    What exactly do you want. What should be lazy loaded/lazy evaluated?? Be more specific.

    Lazy evaluation (as know from other languages) AFAIK is not supported in Javascript per se (as language concept). Except maybe for operators like &, |, &&, ||.

    If you just want some javascript to lazy load other scripts look into this: Painless JavaScript lazy loading with LazyLoad

    0 讨论(0)
  • 2021-02-10 17:34

    Lazy Load does lazy loading of images.

    0 讨论(0)
提交回复
热议问题