当前位置 : 主页 > 网络编程 > JavaScript >

禁止蒙层底部页面跟随滚动

来源:互联网 收集:自由互联 发布时间:2021-06-28
gistfile1.txt Document 打开弹窗 关闭弹窗 // ./stopBodyScroll.js let _stopBodyScroll = {options: {bodyEl: document.body,topIndex: 0},init: function(isFixed) {if (isFixed) {this.options.topIndex = window.scrollYthis.options.bodyEl.sty
gistfile1.txt



	
 
	
 
	
 
	Document
	



	
 
		
  
		
  
		
  
		
  
		
  
		
  
   打开弹窗
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
		
  
	
 
	
 
		
   
    
  
	
 
	
	




// ./stopBodyScroll.js 

let _stopBodyScroll = {
	options: {
		bodyEl: document.body,
		topIndex: 0
	},
	init: function(isFixed) {
		if (isFixed) {
			this.options.topIndex = window.scrollY
			this.options.bodyEl.style.position = 'fixed'
			this.options.bodyEl.style.top = -this.options.topIndex + 'px'
		} else {
			this.options.bodyEl.style.position = ''
			this.options.bodyEl.style.top = ''
			window.scrollTo(0, this.options.topIndex) // 回到原先的top
		}
	}
}
网友评论