js实现分享到随页⾯滚动⽽滑动效果的⽅法本⽂实例讲述了js实现分享到随页⾯滚动⽽滑动效果的⽅法。分享给⼤家供⼤家参考。具体如下:
页⾯向上向下滚动,分享到的模块随着滑动。
要点:
复制代码代码如下:
var scrtop =document.documentElement.scrollTop||document.body.scrollTop;
var height = document.documentElement.clientHeight||document.body.clientHeight;
var top = scrtop + (height - jb51.offsetHeight)/2;
top = parseInt(top);
获得页⾯垂直居中的位置
上代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="gb2312" />
<title>⽆标题⽂档</title>
<style>
body{margin:0; padding:0; font:12px/1.5 arial; height:2000px;}
#jb51{width:100px; height:200px; line-height:200px;
text-align:center; border:1p solid #ccc;
html滚动效果代码background:#f5f5f5; position:absolute; left:-100px; top:0;}
#jb51_tit{position:absolute; right:-20px; top:60px;
width:20px; height:60px; padding:10px 0;
background:#06c; text-align:center;
line-height:18px; color:#fff;}
</style>
<script>
var jb51 = ElementById("jb51");
startrun(jb51,0,"left")
}
startrun(jb51,-100,"left")
}
var scrtop=document.documentElement.scrollTop||document.body.scrollTop;
var height=document.documentElement.clientHeight||document.body.clientHeight;
var top = scrtop + (height - jb51.offsetHeight)/2;
top = parseInt(top);
startrun(jb51,top,"top")
}
}
var timer = null
function startrun(obj,target,direction){
clearInterval(timer);
timer = setInterval(function(){
var speed = 0;
if(direction == "left"){
speed = (target-obj.offsetLeft)/8;
speed = speed>il(speed):Math.floor(speed);
if(obj.offsetLeft == target){
clearInterval(timer);
}else{
obj.style.left = obj.offsetLeft + speed + "px";
}
}
if(direction == "top"){
speed = (target-obj.offsetTop)/8;
speed = speed>il(speed):Math.floor(speed);
if(obj.offsetTop == target){
clearInterval(timer);
}else{
p = obj.offsetTop + speed + "px";
}
document.title = obj.offsetTop + ',' + target + ',' +speed;
}
},30)
}
</script>
</head>
<body>
<div id="jb51">
分享到内容
<span id="jb51_tit">分享到</span>
</div>
</body>
</html>
希望本⽂所述对⼤家的javascript程序设计有所帮助。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论