简体   繁体   中英

Lazy Load For Blog Posts

So I'm trying so so hard to find something for JavaScript or jQuery where I can use a lazy loading plugin or SOMETHING that goes a little like this:

if .post IS_NOT_IN_VIEW do{
dont_load();
 }else{
load();
}

I could've made that better xD. But hopefully you can understand what I mean by that. I just want something that'll STOP the loading of my content with a class of "post" but it'll load it when the user has the content in view.

Thank you if you can help... I had already posted a question like this but people just had problems with the post and I guess people just didn't even bother to look at it seeing it had 6 or 7 comments...

I think ajax addresses your question.

http://api.jquery.com/jquery.ajax/

You can load resources using this.

HTML :

$.ajax({
    method: "get",
    url: "some_url",
    dataType: "html"
})
.done(function( data ) {
    alert( "HTML content: " + html);
});

Or for json just change the dataType to json.

If you want to lazily load javascript :

How to dynamically insert a <script> tag via jQuery after page load?

Has some helpful answers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM