代码之家  ›  专栏  ›  技术社区  ›  Marty

对象定义属性:如何将requestAnimationFrame设置为false?

  •  -2
  • Marty  · 技术社区  · 6 年前

    如何设置 requestAnimationFrame false 在条件语句中测试什么?

    Object.defineProperty(window, 'requestAnimationFrame', {
        value: ()=> {}
    })
    
    
    //need to be tested
    
    if ('requestAnimationFrame' in window === false) {
                window.scroll(0, destinationOffsetToScroll)
                if (callback) {
                    callback()
                }
                return
            }
    1 回复  |  直到 6 年前
        1
  •  0
  •   Nicolas Brugneaux    6 年前

    正如你在评论中所指出的,你是在嘲笑我 window.requestanimationframe行为。我建议你看看 https://github.com/alexreardon/raf-stub https://github.com/FormidableLabs/mock-raf :)

    编辑:

    delete window.requestAnimationFrame;
    'requestAnimationFrame' in window === false
    // true