V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Reign
V2EX  ›  程序员

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

  •  
  •   Reign · 2017-11-15 12:06:13 +08:00 · 1650 次点击
    这是一个创建于 2354 天前的主题,其中的信息可能已经有所发展或是发生改变。

    网址: 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 条回复    2017-11-15 13:38:31 +08:00
    meszyouh
        1
    meszyouh  
       2017-11-15 13:02:56 +08:00
    pjax 听到很蛋疼...
    无非就是 监听 scoll , 判断到底没有啦 , 到底就 通过 ajax 获取数据 , 然后拼接 html。你给的这个例子, 把新生成的元素添加到 大盒子就可以了
    nondanee
        2
    nondanee  
       2017-11-15 13:06:31 +08:00
    ...
    if(xhr.readyState==4&&xhr.status==200){
    $('div').append('blahblah')
    history.replaceState(null,null,"?page="+n)
    ...
    }
    ...
    nondanee
        3
    nondanee  
       2017-11-15 13:08:29 +08:00
    哦,好吧...wallheaven 是用 pushState 的
    ```
    ...
    if(xhr.readyState==4&&xhr.status==200){
    $('div').append('blahblah')
    history.pushState(null,null,"?page="+n)
    ...
    }
    ...
    ```
    oh
        4
    oh  
       2017-11-15 13:38:31 +08:00
    如果大家都那么喜欢吐槽 H5 的话为啥不吐槽一下 PJAX 呢……
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5429 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 08:59 · PVG 16:59 · LAX 01:59 · JFK 04:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.