$(document).scroll(function(){ // 页面加载时,获取滚动条初始高度 var distance = $(document).scrollTop() // 获取滚动条初始高度的值 :0 styleAttrs.forEach(attr => { if (attr !== 'top') { domDialog.css(attr, domPoper.style[attr]) } else if (attr === 'top') { const top = (parseInt(domPoper.style[attr]) - parseInt(distance))+'px' domDialog.css(attr, top) } }) })
https://segmentfault.com/q/1010000003027496
https://www.cnblogs.com/moguzi12345/p/7716861.html