• 请不要在回答技术问题时复制粘贴 AI 生成的内容
Reign
V2EX  ›  程序员

像 wallhaven 这样的瀑布流 pjax 该怎样实现?

  •  
  •   Reign · Nov 15, 2017 · 2126 views
    This topic created in 3126 days ago, the information mentioned may be changed or developed.

    网址: https://alpha.wallhaven.cc/latest

    向下滚动中,网址也在不停的变化,新内容不断 append 到最下面,但是我在 github 上找了一堆 pjax 的库:

    https://github.com/defunkt/jquery-pjax

    https://github.com/welefen/pjax

    都只支持对某个 div 进行内容的替换,而非追加,类似于$('div').html('blahblah')和$('div').append('blahblah')的区别,如果要实现 wallhaven 这样不断将新内容追加到页尾的 pjax,该怎样实现,先谢谢了

    4 replies    2017-11-15 13:38:31 +08:00
    meszyouh
        1
    meszyouh  
       Nov 15, 2017
    pjax 听到很蛋疼...
    无非就是 监听 scoll , 判断到底没有啦 , 到底就 通过 ajax 获取数据 , 然后拼接 html。你给的这个例子, 把新生成的元素添加到 大盒子就可以了
    nondanee
        2
    nondanee  
       Nov 15, 2017
    ...
    if(xhr.readyState==4&&xhr.status==200){
    $('div').append('blahblah')
    history.replaceState(null,null,"?page="+n)
    ...
    }
    ...
    nondanee
        3
    nondanee  
       Nov 15, 2017
    哦,好吧...wallheaven 是用 pushState 的
    ```
    ...
    if(xhr.readyState==4&&xhr.status==200){
    $('div').append('blahblah')
    history.pushState(null,null,"?page="+n)
    ...
    }
    ...
    ```
    oh
        4
    oh  
       Nov 15, 2017
    如果大家都那么喜欢吐槽 H5 的话为啥不吐槽一下 PJAX 呢……
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4207 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 00:59 · PVG 08:59 · LAX 17:59 · JFK 20:59
    ♥ Do have faith in what you're doing.