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

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

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