前端手册程序员

Safari中JS控制页面滚动失效

2018-08-16  本文已影响51人  SPEIKE
 $(document).on('click','.nav li', function(e){
      var id = $(this).attr('data-id')
      if (id === 'index') {
        $(document).scrollTop(0)
        window.location.reload()
        return
      }
      if (id === 'notice') {
        return
        // window.location.href = 
      }
      var leng = $('#'+id).offset().top - 99
// 错误写法
// 这种写法 在window电脑中没有任何问题, 但在Safari中不支持
      $('html').animate({
        'scrollTop':  leng
      },400)
      e.preventDefault()
    })
// 兼容写法
    $('html,body').animate({
        'scrollTop':  leng
      },400)
      e.preventDefault()
    })
上一篇 下一篇

猜你喜欢

热点阅读