geeeger / blog

https://loofp.com
1 stars 0 forks source link

sticky position 支持检测方式 #11

Open geeeger opened 4 years ago

geeeger commented 4 years ago
 definePosition () {
    let stickyProp
    if (this.props.useFixed) {
      stickyProp = 'fixed'
    } else {
      const prefix = ['', '-o-', '-webkit-', '-moz-', '-ms-']
      const test = document.head.style
      for (let i = 0; i < prefix.length; i += 1) {
        test.position = `${prefix[i]}sticky`
      }
      stickyProp = test.position ? test.position : 'fixed'
      test.position = ''
    }
    return stickyProp
  }

来自stickybits.js