4

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 when this event happens, the postponed code should get executed only once. Some kind of lazy initialization.

For example, apply some animation to an element not when document is ready, but when user hovers over that element.

I know how to do it the manual way but I don't like it because I have to think about checking and setting 'initialized' flag before executing anonymous function. I was wondering if it's already done (bug free, with some tasty features).

0

3 Answers 3

4

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).

Sign up to request clarification or add additional context in comments.

2 Comments

Interesting find. But one question comes to mind. (Sorry) How much time did you spend on finding this instead of coding ;)
About 5 minutes actually. It's not the matter of saved time. It's pure developer's curiosity and willing to communicate. That's what the stackoverflow is for, isn't it? :)
2

Lazy Load does lazy loading of images.

Comments

2

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

3 Comments

Edited my question. It's more specific now.
@Justin Johnson: I suppose you talk about the LazyLoad script. Did you try if it works in IE8? I guess it simply hasn't been tested for newer versions IE8, Chrome, Opera10. Maybe contact author and suggest updating supported browser version info
Hm... Yeah, there is jQuery.one (docs.jquery.com/Events/one#typedatafn) that does the same and runs great. Unfortunately, won't help in non-trivial cases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.