0
点赞
收藏
分享

微信扫一扫

让一个层固定在网页的某个位置

勇敢乌龟 2022-07-27 阅读 169

<DIV id=lovexin0 style='Z-INDEX: 100; left: 10px; POSITION: absolute; TOP: 400px;'> 
<img src="图片地址"></DIV>
<script language=javascript>
lastScrollY=0;
function heartBeat0(){
diffY=document.body.scrollTop;
percent=.1*(diffY-lastScrollY);
if(percent>0)percent=Math.ceil(percent);
else percent=Math.floor(percent);
document.all.lovexin0.style.pixelTop+=percent;
lastScrollY=lastScrollY+percent;}
window.setInterval("heartBeat0()",1);
</script>

把这些代码放在<body></body>之间
第一行最后那个数字 TOP: 400px 这个400px 是就是你图片的顶端和网页的顶端之间的距离可任意修改


举报

相关推荐

0 条评论