简体   繁体   English

博客帖子的延迟加载

[英]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: 因此,我正在努力寻找适合JavaScript或jQuery的东西,可以在其中使用惰性加载插件或类似以下内容的东西:

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

I could've made that better xD. 我本可以制作出更好的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. 我只想要一些可以停止用“ post”类加载我的内容的东西,但是它将在用户查看内容时加载它。

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... 谢谢您的帮助。我已经发布了这样的问题,但是人们对帖子有疑问,我想人们甚至不屑于看它,看到它有6或7条评论...

I think ajax addresses your question. 我认为ajax解决了您的问题。

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

You can load resources using this. 您可以使用此资源加载资源。

HTML : 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. 或者对于json,只需将dataType更改为json。

If you want to lazily load javascript : 如果您想懒加载javascript

How to dynamically insert a <script> tag via jQuery after page load? 页面加载后如何通过jQuery动态插入<script>标签?

Has some helpful answers. 有一些有用的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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