JS实现右侧悬浮框效果本⽂实例为⼤家分享了JS实现右侧悬浮框效果的具体代码,供⼤家参考,具体内容如下让⼀个div始终悬浮在右下⾓
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#div1{
width: 100px;
height: 150px;
background: red;
position: absolute;
bottom: 0px;
right: 0px;
}
</style>
<script>
var oDiv = ElementById('div1');
var scrollTop =document.documentElement.scrollTop||document.body.scrollTop;//浏览器兼容
startmove(document.documentElement.clientHeight - oDiv.offsetHeight + scrollTop)
// document.documentElement.clientHeight 页⾯可视区⾼度
}
var timer = null;
//悬浮框缓冲运动
function startmove(iTarget){
var oDiv = ElementById('div1');
clearInterval(timer);
timer = setInterval(function(){
var speed = (iTarget-oDiv.offsetTop)/4;
speed = speed>il(speed):Math.floor(speed);
if(oDiv.offsetTop == iTarget){
clearInterval(timer);
}
else{
p = oDiv.offsetTop +speed+'px';
}
},30)
}
</script>
</head>
<body >
<div id="div1"></div>网站底部代码js特效
</body>
</html>
对联悬浮
让div悬浮在右侧中间
只需要更改start move()函数中的数据
startmove(parseInt((document.documentElement.clientHeight - oDiv.offsetHeight )/2)+ scrollTop)//对联悬浮以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。