推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
iugo

通过 .classList.add('') 增加的 class (在移动端 WebKit)无法通过 .classList.remove('') 移除是为什么? 增加一个 class 的本质是什么?

  •  
  •   iugo · Apr 27, 2015 · 3536 views
    This topic created in 4060 days ago, the information mentioned may be changed or developed.
    一个简单的例子:
    http://codepen.io/iugo/pen/pJveKZ

    一个实用的例子:
    http://codepen.io/iugo/pen/aOzJRe

    简单的例子在 Firefox 和移动端都很好地实现了功能.

    但是实用的例子在 Firefox 实现了功能, 但在移动端却无法移除 class, 导致功能缺失.

    测试环境:
    Firefox: Ubuntu(64bit) 37
    移动端: iOS 8(Safari) and Android 4.4(Chrome)
    9 replies    2015-04-27 15:38:13 +08:00
    iugo
        1
    iugo  
    OP
       Apr 27, 2015
    简单的例子在 Android 4.4(Chrome) 上正常.
    但是在 iOS 8(Safari) 上不正常.
    morethansean
        2
    morethansean  
       Apr 27, 2015
    iugo
        3
    iugo  
    OP
       Apr 27, 2015
    @morethansean 应该不是这么简单的问题.

    如果需要移除 html 中写的 class, 则没有问题.
    但如果使用一个函数向 classList 中增加 class, 则 Firefox 正常, WebKit 无法实现.
    otakustay
        4
    otakustay  
       Apr 27, 2015   ❤️ 1
    iOS safari就没触发scroll事件,不是classList的问题……
    iugo
        6
    iugo  
    OP
       Apr 27, 2015
    @otakustay 移动端由 scroll 类似的事件吗? 或有什么库推荐吗?
    iugo
        7
    iugo  
    OP
       Apr 27, 2015
    @otakustay 简单的例子和实用的例子在 Chrome(Android) 里也是有区别的.

    在简单的例子中:
    只要滑动就触发了事件绑定的函数.

    在实用的例子中:
    滑动后需要在空白处点击一下才触发.

    这个是什么情况?
    otakustay
        8
    otakustay  
       Apr 27, 2015   ❤️ 1
    @iugo Stackoverflow上有些相关的问题

    http://stackoverflow.com/questions/9225525/how-can-i-monitor-scroll-position-while-scrolling-in-safari-on-ios

    总得来说乖乖touchstart的时候开始setInterval判断scrollTop……
    otakustay
        9
    otakustay  
       Apr 27, 2015   ❤️ 1
    @iugo 厄,我没有android的手机……我看有时间的话去借一个来帮你看看问题- -
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   943 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 20:43 · PVG 04:43 · LAX 13:43 · JFK 16:43
    ♥ Do have faith in what you're doing.