模拟实现fixed效果

gkw521 gkw521 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
JS模拟fixed效果。如何解决晃动问题。也就是跟fixed效果一摸一样。
既然fixed浏览器已经实现,真的就没办法模拟出来吗?!!

<div style="width:100%;height:2000px;border:1px red solid;"></div>
<div id="test" style="position:absolute;left:50px;top:0px;background:url(http://avatar.profile.csdn.net/F/4/2/2_gkw521.jpg);width:100px;height:100px;"></div>
<script>
var dom=document.getElementById('test');
var mark=true,timeID,num=0;;
var setPos=function(){
markf=false;
clearInterval(timeID);
timeID=setInterval(function(){
dom.style.top=(document.documentElement.scrollTop+document.documentElement.clientHeight-dom.offsetHeight)+'px';
num++;
document.title=num;
//if(num>1000){num=0;clearInterval(timeID);}
},100);
}
setPos();
//window.onscroll=window.onresize=setPos;
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
gkw521
JavaScript 87,984 成员 224,681 内容