指定位置悬浮封装

Js
function menuFixed(id){
  var obj = document.getElementById(id);
  var _getHeight = obj.offsetTop;
  window.onscroll = function(){
    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    if(scrollTop == _getHeight){
      obj.style.position = 'relative';
    }else{
      obj.style.position = 'fixed';
    }
  }
}
Html

你可能感兴趣的:(指定位置悬浮封装)