kisnows
V2EX  ›  问与答

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

  •  2
     
  •   kisnows · Sep 13, 2015 · 5107 views
    This topic created in 3887 days ago, the information mentioned may be changed or developed.

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

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

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

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

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

    @ccccccc
    图好像没上传上去
    ccccccc
        49
    ccccccc  
       Sep 16, 2015
    @kisnows 是的,手离开触摸板事件还在触发,这个就是 '缓冲' 的过程
    kisnows
        50
    kisnows  
    OP
       Sep 16, 2015
    @ccccccc 还真是这样,我还得想想怎么弄。
    kisnows
        51
    kisnows  
    OP
       Sep 18, 2015
    @l12ab 现在应该可以滚动了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5814 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 94ms · UTC 01:57 · PVG 09:57 · LAX 18:57 · JFK 21:57
    ♥ Do have faith in what you're doing.