如何申请的tumblr像按钮状态后装入无限滚动新的一页 [英] How to request Tumblr like button status after a new page is loaded with infinite scroll

查看:203
本文介绍了如何申请的tumblr像按钮状态后装入无限滚动新的一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是从的tumblr文档中的指令:

Tumblr.LikeButton.get_status_by_page(N):请求帖子的新页面后,调用此函数。将取得在刚刚加载为整数的页号

Tumblr.LikeButton.get_status_by_post_ids([N,N,N]):请像个别职位的状态。需要交ID数组

这个问题已经被问过几次与解决方案<一href="http://stackoverflow.com/questions/16390193/using-tumblr-like-button-with-infinite-scroll/16396022">here和<一href="http://stackoverflow.com/questions/18245238/tumblr-like-button-not-working-after-infinite-scroll-ajax-recall">here两个答案可以告诉你如何请求像帖子的ID按钮状态。那么,有没有更简单,更快的解决方案?

  

我会分享我如何做到这一点,请分享你的观点了。

解决方案

什么是在公认的答案发生<一href="http://stackoverflow.com/questions/18245238/tumblr-like-button-not-working-after-infinite-scroll-ajax-recall">here是:

  1. 首先,你必须给ID来所有的帖子。
  2. 在加载新的职位,找到所有元素(职位)与类(。员额)。
  3. 获取的新职位的ID。
  4. 请求像按钮的状态与新岗位的ID阵列

现在,这是你如何能要求像按钮状态后装入页码新的一页。

  1. 在首先获得页面的职位数量。
  2. 再次获得职位的数量装载新的职位后,
  3. 将帖子的最初数除以职位目前的数字来获取页码。
  4. 要求像页码按钮状态。

        

     变量$ initialNumberOfPosts = $('后')的长度; //获取帖子数
    
        $('#帖)。infinitescroll({
          加载:{
            MSGTEXT:中..
            IMG:/loading_image.gif
            finishedMsg:结束!
          },
            navSelector:#pagination
            nextSelector:#nextpage
            itemSelector:.POST
        },
        功能(newElements){
    
            变量$ currentNumberOfPosts = $('后')的长度。 //获取帖子的电流数量
    
            VAR的PageNumber = Math.ceil($ currentNumberOfPosts / $ initialNumberOfPosts); //获取页码
    
            Tumblr.LikeButton.get_status_by_page(页面编号); //请求像按钮状态
        });
     

*使用(.ceil),因为用户可能会选择每页15个职位,但也可以小于在最后一页。

更新:2014年3月5日

他们的是更简单的方法使用的tumblr变量来获取页面数量,增加其新的页面加载时。请尝试以下操作:

  1. 在首先使用的tumblr变量得到页号:{}当前为
  2. 在一个新的页面加载增加当前页码。
  3. 要求像当前页码按钮状态。

        

      VAR的PageNumber = {当前页}; //获取当前页码(将外部文件无法正常工作)
    
        $('#帖)。infinitescroll({
          加载:{
            MSGTEXT:中..
            IMG:/loading_image.gif
            finishedMsg:结束!
          },
            navSelector:#pagination
            nextSelector:#nextpage
            itemSelector:.POST
        },
        功能(newElements){
    
            编号和副++; //获取页码加载新的页面后。
    
            Tumblr.LikeButton.get_status_by_page(页面编号); //请求像按钮状态
        });
     

//结束更新。

*这是你如何要求像保罗爱尔兰的无限滚动按钮状态的示例脚本。

因此​​,在这两种方式,它是大约3 - 4个步骤。我的解决办法似乎更容易设置了我,所以我使用它。您可以使用什么似乎更好的给你。

我觉得我的解决方案是快的原因,它使用简单的功能,但是这正是我想;我没有任何证据了。谢谢!

This is the instruction from Tumblr documentation:

Tumblr.LikeButton.get_status_by_page(n): Call this function after requesting a new page of Posts. Takes the page number that was just loaded as an integer.

Tumblr.LikeButton.get_status_by_post_ids([n,n,n]): Request Like status for individual posts. Takes an array of post IDs.

This question has been asked few times with solutions here and here both answers can tell you how to request like button status with post IDs. So is there a easier and probably faster solution?

I'll share how i do it, please share your opinions too.

解决方案

What's happening in the accepted answer here is:

  1. First you have to give IDs to all the posts.
  2. After new posts are loaded, find all the elements(posts) with class (.post).
  3. Get IDs of the new posts.
  4. Request like button status with array of new post IDs

Now this is how you can request like button status after new page is loaded with page numbers.

  1. First get number of posts in the page.
  2. Get number of the posts again after new posts are loaded.
  3. Divide current numbers of posts by initial number of posts to get the page number.
  4. Request like button status with page number.

        var $initialNumberOfPosts = $('.post').length; // Get number of posts
    
        $('#posts').infinitescroll({
          loading: {
            msgText: "Loading..",
            img: "/loading_image.gif",
            finishedMsg: "End!"
          },
            navSelector  : "#pagination",
            nextSelector : "#nextpage",
            itemSelector: ".post"
        },
        function(newElements) {
    
            var $currentNumberOfPosts = $('.post').length; // Get current number of posts
    
            var pageNumber = Math.ceil($currentNumberOfPosts / $initialNumberOfPosts); // Get page number
    
            Tumblr.LikeButton.get_status_by_page(pageNumber); // Request like button status
        });
    

*Using (.ceil) because user might have selected 15 posts per page but there can be less than that in the last page.

Update: March 5, 2014.

Their is more simple way to get the page number using Tumblr variable and increase it when the new page loads. Try the following:

  1. First get the page number using Tumblr variable: {CurrentPage}.
  2. After a new page is loaded increase the current page number.
  3. Request like button status with current page number.

        var pageNumber = {CurrentPage}; // Get current Page number ( Will not work in external file)
    
        $('#posts').infinitescroll({
          loading: {
            msgText: "Loading..",
            img: "/loading_image.gif",
            finishedMsg: "End!"
          },
            navSelector  : "#pagination",
            nextSelector : "#nextpage",
            itemSelector: ".post"
        },
        function(newElements) {
    
            pageNumber++; // Get page number after new page is loaded.
    
            Tumblr.LikeButton.get_status_by_page(pageNumber); // Request like button status
        });
    

// End update.

*This is an example script for how you can request like button status with Paul Irish's infinite scroll.

So in both way, it's roughly 3 - 4 steps. My solution seems easier to set up for me so i use it. You can use what seems better to you.

I think my solution is faster 'cause it uses simple functions, but that's just what i think; i don't have any evidence for now. Thank you!

这篇关于如何申请的tumblr像按钮状态后装入无限滚动新的一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆