如何申请的tumblr像按钮状态后装入无限滚动新的一页按钮、状态、tumblr

2023-09-10 19:49:23 作者:为你心软。

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

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

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

这个问题已经被问过几次与解决方案here和here两个答案可以告诉你如何请求像帖子的ID按钮状态。那么,有没有更简单,更快的解决方案?

  

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

解决方案

什么是在公认的答案发生here是:

首先,你必须给ID来所有的帖子。 在加载新的职位,找到所有元素(职位)与类(。员额)。 获取的新职位的ID。 请求像按钮的状态与新岗位的ID阵列 易语言的软件设定随系统自动启动没有成功 求助

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

在首先获得页面的职位数量。 再次获得职位的数量装载新的职位后, 将帖子的最初数除以职位目前的数字来获取页码。

要求像页码按钮状态。

    

 变量$ 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变量来获取页面数量,增加其新的页面加载时。请尝试以下操作:

在首先使用的tumblr变量得到页号:{}当前为 在一个新的页面加载增加当前页码。

要求像当前页码按钮状态。

    

  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:

First you have to give IDs to all the posts. After new posts are loaded, find all the elements(posts) with class (.post). Get IDs of the new posts. 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.

First get number of posts in the page. Get number of the posts again after new posts are loaded. Divide current numbers of posts by initial number of posts to get the page number.

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:

First get the page number using Tumblr variable: {CurrentPage}. After a new page is loaded increase the current page number.

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!

 
精彩推荐
图片推荐