js添加广告模块,随页面移动而移动

 2023-09-10 阅读 31 评论 0

摘要:实现如下的效果,一般用于广告, 这是通过运动来实现的,大家可以先自己写写,再看看和小编我写的是不是同一个思想 <style>#div1{width:100px;height:100px;background:red;position:absolute;bottom:0;right:0;} </style><body sty

实现如下的效果,一般用于广告,

这是通过运动来实现的,大家可以先自己写写,再看看和小编我写的是不是同一个思想

<style>#div1{width:100px;height:100px;background:red;position:absolute;bottom:0;right:0;}
</style><body style="height:2000px;"><div id="div1"></div>
</body>

js代码部分

<script>window.οnscrοll=function(){var div=document.getElementById("div1");var scrollTop=document.documentElement.scrollTop ||document.body.scrollTop;// div.style.top=document.documentElement.clientHeight-div.offsetHeight+scrollTop+'px';startmove (parseInt((document.documentElement.clientHeight-div.offsetHeight)/2+scrollTop))         //offsetHeight是div的高度//document.documentElement.clientHeight是到窗口的顶部};var timer=null;function startmove(iTarget){var div=document.getElementById('div1');clearInterval(timer);timer=setInterval(function(){var speed =(iTarget-div.offsetTop)/4;speed=speed>0?Math.ceil(speed):Math.floor(speed);  if (div.offsetTop==iTarget)   {clearInterval(timer);}else{div.style.top=div.offsetTop+speed+'px';}}, 30)   }</script>

  

js导入模块,转载于:https://www.cnblogs.com/biyongyao/p/5847797.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/37653.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息