V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
kisnows
V2EX  ›  问与答

写了一个简单的 fullpage 框架,希望大家提提意见

  •  2
     
  •   kisnows · 2015-09-13 20:14:19 +08:00 · 4163 次点击
    这是一个创建于 3119 天前的主题,其中的信息可能已经有所发展或是发生改变。

    写了一个fullpage前端框架,可以很轻松创建的单页滑动网站,不依赖任何库。
    这是一个简单的 DEMO:http://kisnows.com/fullpage-light.js/.

    因为不知道还需要那些功能,所以发上来希望大家提提意见。

    顺便请教一个问题,关于 chrome 开发工具的:
    以前在开发工具的 js 文件上里面点右键,会出现 block 这个文件的选项,也就是说在 debug 的时候不会跳入被 block 的文件,很方便跳过那写引入的库或这个框架文件。
    但是现在没有了,只能在设置里面手动去加,这样明显很麻烦,为什么 chrome 要这么做?
    chrome 版本: 45.0.2454.85 m

    第 1 条附言  ·  2015-09-14 19:47:13 +08:00
    感谢大家提出的意见,现在已经解决了滚动抽搐的问题。
    第 2 条附言  ·  2015-09-18 17:08:07 +08:00
    现在支持 ie9+和 firefox 了。
    至于 v 友说的 mac 下触摸板的问题,暂时没有找到合适的解决方法。
    第 3 条附言  ·  2016-02-21 20:54:26 +08:00
    最近用 ES6 重构了整个项目,感觉维护起来方便多了。
    51 条回复    2015-09-18 17:08:30 +08:00
    emric
        1
    emric  
       2015-09-13 20:29:30 +08:00
    一直滚鼠标滚轴会出现问题.
    just44
        2
    just44  
       2015-09-13 20:39:08 +08:00
    滚动的时候页面一直在抽搐。。。
    haiyang416
        3
    haiyang416  
       2015-09-13 20:39:09 +08:00 via Android
    安卓平板不能点击超链接
    kisnows
        4
    kisnows  
    OP
       2015-09-13 20:41:47 +08:00
    @emric 是不是页面很快的滚下去然后又回到原位?
    kisnows
        5
    kisnows  
    OP
       2015-09-13 20:43:54 +08:00
    @just44 什么设备?抽搐能具体描述一下吗,我好分析下问题,谢啦 o (∩_∩)o
    kisnows
        6
    kisnows  
    OP
       2015-09-13 20:53:08 +08:00
    @haiyang416 我只使用了最普通的 a 链接,不应该啊
    haiyang416
        7
    haiyang416  
       2015-09-13 20:57:33 +08:00 via Android
    @kisnows 我的安卓手机也不行,试了 Firefox 和 Opera 。
    ak47iej
        8
    ak47iej  
       2015-09-13 21:07:51 +08:00
    滚动抽搐 +1
    chrome 42 ,滚一下动一下没问题
    问题是...我用滚轮是连续一直滚,然后就抽搐了
    问题貌似是滚太多直接到底,然后 js 回顶部再滚,再到底...
    呃,貌似描述的不太好..
    TangMonk
        9
    TangMonk  
       2015-09-13 21:24:27 +08:00
    滚动抽搐 +2

    macbook, 触控板手势向下滑动
    Starduster
        10
    Starduster  
       2015-09-13 21:55:07 +08:00
    和 9 楼相同, Mac ,触摸板滚动, chrome
    力度大就没问题,力度小了就抽搐,而且会弹回去
    kisnows
        11
    kisnows  
    OP
       2015-09-13 22:43:30 +08:00
    @Starduster
    @ak47iej
    @TangMonk
    因为我开了循环滚动,这样由于你们滚动速度过快,同时响应了 N 次,而且滚到最后一页的时候会自动回到第一页,所以看起来会抽搐。
    看来我要加个限制,比如多少秒内只相应一次操作,这样应该就不会抽搐了。
    kisnows
        12
    kisnows  
    OP
       2015-09-13 22:48:46 +08:00
    @haiyang416 我找找问题,虽然不太能理解为什么
    ljbha007
        13
    ljbha007  
       2015-09-13 23:24:59 +08:00
    不能连续滚动而是松手才能到下一页 这一点体验不好
    用 translate3d 做是很简单的
    Kilerd
        14
    Kilerd  
       2015-09-13 23:34:52 +08:00   ❤️ 1
    为什么不设置当前动作未结束时,拒绝(忽略)其他动作。
    boro
        15
    boro  
       2015-09-13 23:55:22 +08:00
    滚动抽搐 +1 , 滑动不顺畅。
    l12ab
        16
    l12ab  
       2015-09-13 23:58:06 +08:00
    PC, FIREFOX, 滚不动
    moosoome
        17
    moosoome  
       2015-09-14 02:16:29 +08:00
    抽搐....大概是滚动未结束就接受了其他动作
    kisnows
        18
    kisnows  
    OP
       2015-09-14 08:43:36 +08:00
    @ljbha007
    @Kilerd
    @boro
    @l12ab
    @moosoome
    因为我开了循环滚动,这样由于你们滚动速度过快,同时响应了 N 次,而且滚到最后一页的时候会自动回到第一页,所以看起来会抽搐。
    接下来我会加个限制,再一次滚动完成之前,不响应其它的操作,这样应该就不会抽搐了。
    还有我这里只会在 ie 上才会抽搐,所以一开始没在意。
    kisnows
        19
    kisnows  
    OP
       2015-09-14 08:44:38 +08:00
    @l12ab firefox 滚不动是我没有对 firefox 做兼容-_-,你可以试着用键盘控制下。接下来我会对 firefox 做兼容。
    sarices
        20
    sarices  
       2015-09-14 09:23:38 +08:00
    貌似鼠标滚动不是很顺畅 chrome ,有点抽搐,需要优化一下
    learnshare
        21
    learnshare  
       2015-09-14 09:46:58 +08:00
    Demo 不能太丑
    Havee
        22
    Havee  
       2015-09-14 10:07:35 +08:00
    safari 触摸板滚动,极其颤抖。
    kisnows
        23
    kisnows  
    OP
       2015-09-14 10:58:46 +08:00
    @learnshare Demo 其实是在针对手机端的。要不提供个设计思路,毕竟我不是做设计的额,-_-。
    mhtt
        24
    mhtt  
       2015-09-14 13:16:31 +08:00
    chrome 45 触板滚动,异常颤抖
    akaayy
        25
    akaayy  
       2015-09-14 18:28:02 +08:00 via Android   ❤️ 1
    我觉得非常好 楼主继续加油!
    kisnows
        26
    kisnows  
    OP
       2015-09-14 19:46:08 +08:00
    @ak47iej
    @TangMonk
    @Starduster
    @ljbha007
    @Kilerd
    @boro
    @moosoome
    @sarices
    @Havee
    已经解决了抽搐的问题,现在在页面滚动完成之前是不会相应下一次动作的
    kisnows
        27
    kisnows  
    OP
       2015-09-14 19:47:35 +08:00
    @haiyang416 你现在再试试,应该好了。
    kisnows
        28
    kisnows  
    OP
       2015-09-14 19:49:45 +08:00
    @emric 现在应该不会了,已经解决了这个问题。
    kisnows
        29
    kisnows  
    OP
       2015-09-14 19:50:59 +08:00
    @just44 现在不会抽搐了,^_^
    @haiyang416 手机上不能超链接,是因为之前手误把 touch 的默认事件给禁止掉了,现在应该可以了
    Kilerd
        30
    Kilerd  
       2015-09-14 21:51:15 +08:00
    现在看上去起码可以用了,但是感觉还是怪怪的。
    kisnows
        31
    kisnows  
    OP
       2015-09-14 23:21:25 +08:00
    @Kilerd 能说说怪在那里呢?这样我好修改
    Starduster
        32
    Starduster  
       2015-09-15 00:03:43 +08:00
    那么现在的问题就是我轻轻一滚只要不在中途再按住触摸板他会一直滚到最下面,难道说就是这么设计的?
    kisnows
        33
    kisnows  
    OP
       2015-09-15 09:10:22 +08:00
    应该不会吧,我在我这边测了下,没有这个问题。我是 win 的本和触摸板
    ccccccc
        34
    ccccccc  
       2015-09-15 09:19:09 +08:00   ❤️ 1
    @kisnows mac 触摸板会有一个 '缓冲' 的行为, 具体表现是很多次触发滚动. 这个不是简单加条件限制可以组织的, 你可以参考一下另一个 fullPage 插件的做法.
    kisnows
        35
    kisnows  
    OP
       2015-09-15 09:30:56 +08:00
    @ccccccc 我现在的做法是,在一次动作完成之前,都不会相应其它的动作。这样应该不会有问题,在页面还有滚动完成之前,它是不会触发任何动作的。
    手头没有 mac ,不好测试-_-
    ccccccc
        36
    ccccccc  
       2015-09-15 10:37:52 +08:00   ❤️ 1
    @kisnows 你现在这样的做法还是没办法阻止 mac 上多次滚动问题, 当你完成一个滚动动作时候, 事实上那个触摸板的滚动事件还在触发, 所以才有多次滚动问题.
    kisnows
        37
    kisnows  
    OP
       2015-09-15 10:57:08 +08:00
    @ccccccc 滚动还在触发,是说手已经离开触摸板了,但是触摸事件还在触发吗?要是这样的话,我可能得考虑从一个方向入手了。
    ccccccc
        38
    ccccccc  
       2015-09-15 11:30:57 +08:00   ❤️ 1
    在 mac 上 window.onscroll = function (e ) {console.log (e )}

    然后轻轻滑动触摸板, console 输出下面

    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    VM127:2 Event {}
    kisnows
        39
    kisnows  
    OP
       2015-09-15 12:46:58 +08:00
    @ccccccc 我晚上下班了试试看能不能搞定
    kisnows
        40
    kisnows  
    OP
       2015-09-15 23:28:09 +08:00 via iPhone
    @ccccccc 你现在再看一下 应该好了
    kisnows
        41
    kisnows  
    OP
       2015-09-15 23:31:20 +08:00 via iPhone
    @Starduster 现在应该没有这个问题了
    kisnows
        42
    kisnows  
    OP
       2015-09-15 23:32:49 +08:00 via iPhone
    @Kilerd 之前没考虑到限制 现在加上了 谢谢意见
    kisnows
        43
    kisnows  
    OP
       2015-09-15 23:33:51 +08:00 via iPhone
    @akaayy 谢谢鼓励
    ccccccc
        44
    ccccccc  
       2015-09-16 09:47:12 +08:00
    @kisnows 在 mac 上触摸板上多次滚动还是有问题, 下面代码是另一个 fullpage 插件的做法

    // https://github.com/alvarotrigo/fullPage.js
    // Gets the average of the last `number` elements of the given array.
    function getAverage (elements, number ) {
    var sum = 0;

    //taking `number` elements from the end to make the average, if there are not enought, 1
    var lastElements = elements.slice (Math.max (elements.length - number, 1 ));

    for (var i = 0; i < lastElements.length; i++) {
    sum = sum + lastElements[i]
    }

    return Math.ceil (sum/number );
    }

    var prevtime = new Date ().getTime ();
    $(document ).on ('mousewheel wheel DOMMouseScroll', function (e ) {
    e.preventDefault ()

    var curtime = new Date ().getTime ();

    var value = e.wheelDelta || -e.deltaY || -e.detail;
    var delta = Math.max (-1, Math.min (1, value ));

    //Limiting the array to 150 (lets not waste memory!)
    if (scrollings.length > 149 ) {
    scrollings.shift ()
    }

    //keeping record of the previous scrollings
    scrollings.push (Math.abs (value ))

    //time difference between the last scroll and the current one
    var timeDiff = curtime-prevtime;
    prevtime = curtime;

    //haven't they scrolled in a while?
    //(enough to be consider a different scrolling action to scroll another section )
    if (timeDiff > 200 ) {
    //emptying the array, we dont care about old scrollings for our averages
    scrollings = [];
    }

    if (canScroll ) {
    var averageEnd = getAverage (scrollings, 10 );
    var averageMiddle = getAverage (scrollings, 70 );
    var isAccelerating = averageEnd >= averageMiddle;

    //to avoid double swipes...
    if (isAccelerating ) {
    //scrolling down?
    if (delta < 0 ) {
    hash ('down')

    //scrolling up?
    } else {
    hash ('up')
    }
    }
    }
    })
    kisnows
        45
    kisnows  
    OP
       2015-09-16 10:11:00 +08:00
    @ccccccc 那现在的问题是什么能描述一下吗,还是跟之前一样吗?
    ccccccc
        46
    ccccccc  
       2015-09-16 10:54:48 +08:00
    @kisnows 就是轻轻滑动一下触摸板,然后页面会滚动几个页面
    kisnows
        47
    kisnows  
    OP
       2015-09-16 11:15:29 +08:00
    @ccccccc 看来我还是没有解决这个问题啊,( ▼-▼ )。我现在是这样的。
    [:图片 1:]
    其实的`page.isScrolling`是一个用来判断当前页面是否在滚动的参数。理论上再一次滑动(虽然 wheelEvent 会触发很多次)中只会触发一次,如果说现在是一次滑动走了好几张页面。那有可能是 mac 的触摸板有一个缓冲的过程,就是说即便你手里开了触摸板,但是事件还是触发?
    我得想个其它方法了
    kisnows
        48
    kisnows  
    OP
       2015-09-16 11:16:37 +08:00

    @ccccccc
    图好像没上传上去
    ccccccc
        49
    ccccccc  
       2015-09-16 11:24:53 +08:00
    @kisnows 是的,手离开触摸板事件还在触发,这个就是 '缓冲' 的过程
    kisnows
        50
    kisnows  
    OP
       2015-09-16 11:32:01 +08:00
    @ccccccc 还真是这样,我还得想想怎么弄。
    kisnows
        51
    kisnows  
    OP
       2015-09-18 17:08:30 +08:00
    @l12ab 现在应该可以滚动了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2959 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 15:07 · PVG 23:07 · LAX 08:07 · JFK 11:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.