回到顶部代码,不滚动的时候隐藏,滚动网页后就显示
之前用的是这里的代码http://zhidao.baidu.com/question/193575432.html但是没有,不滚动的时候隐藏“回到顶部”,滚动后显示“回到...
之前用的是这里的代码 http://zhidao.baidu.com/question/193575432.html
但是没有,不滚动的时候隐藏“回到顶部”,滚动后显示“回到顶部”
目前的HTML代码,求修改后的代码
<div id="back-to-top"><script>
lastScrollY=0;
function heartBeat(){
var diffY;
if (document.documentElement && document.documentElement.scrollTop)
diffY = document.documentElement.scrollTop;
else if (document.body)
diffY = document.body.scrollTop
else
{/*Netscape stuff*/}
percent=.1*(diffY-lastScrollY);
if(percent>0)percent=Math.ceil(percent);
else percent=Math.floor(percent);
document.getElementById("full").style.top=parseInt(document.getElementById("full").style.top)+percent+"px";
lastScrollY=lastScrollY+percent;
}
suspendcode="<div id=\"full\" style='right:20px;POSITION:absolute;TOP:320px;z-index:100'><a onclick='window.scrollTo(0,0);'><div class=\"to-top\">TOP</div></a><br></div>"
document.write(suspendcode);
window.setInterval("heartBeat()",1);
</script></div> 展开
但是没有,不滚动的时候隐藏“回到顶部”,滚动后显示“回到顶部”
目前的HTML代码,求修改后的代码
<div id="back-to-top"><script>
lastScrollY=0;
function heartBeat(){
var diffY;
if (document.documentElement && document.documentElement.scrollTop)
diffY = document.documentElement.scrollTop;
else if (document.body)
diffY = document.body.scrollTop
else
{/*Netscape stuff*/}
percent=.1*(diffY-lastScrollY);
if(percent>0)percent=Math.ceil(percent);
else percent=Math.floor(percent);
document.getElementById("full").style.top=parseInt(document.getElementById("full").style.top)+percent+"px";
lastScrollY=lastScrollY+percent;
}
suspendcode="<div id=\"full\" style='right:20px;POSITION:absolute;TOP:320px;z-index:100'><a onclick='window.scrollTo(0,0);'><div class=\"to-top\">TOP</div></a><br></div>"
document.write(suspendcode);
window.setInterval("heartBeat()",1);
</script></div> 展开
2个回答
展开全部
sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />sadfjasdkf<br />asdfjlk<br />
<script language="javascript">
lastScrollY=0;
function heartBeat(){
var diffY;
if (document.documentElement && document.documentElement.scrollTop)
diffY = document.documentElement.scrollTop;
else if (document.body)
diffY = document.body.scrollTop
else
{/*Netscape stuff*/}
percent=.1*(diffY-lastScrollY);
if(percent>0)percent=Math.ceil(percent);
else percent=Math.floor(percent);
document.getElementById("full").style.top=parseInt(document.getElementById("full").style.top)+percent+"px";
lastScrollY=lastScrollY+percent;
if(lastScrollY<200)
{
document.getElementById("full").style.display="none";
}
else
{
document.getElementById("full").style.display="block";
}
}
var gkuan=document.body.clientWidth;
var ks=(gkuan-960)/2-30;
suspendcode="<div id=\"full\" style='right:"+ks+"px;POSITION:absolute;TOP:200px;z-index:100;width:22px; height:58px;cursor:pointer;padding-top:25px; text-align:center; font-size:12px; line-height:14px; color:#4f576c;'><a onclick='window.scrollTo(0,0);'>返回顶部</a></div>"
document.write(suspendcode);
window.setInterval("heartBeat()",1);
</script>
<script language="javascript">
lastScrollY=0;
function heartBeat(){
var diffY;
if (document.documentElement && document.documentElement.scrollTop)
diffY = document.documentElement.scrollTop;
else if (document.body)
diffY = document.body.scrollTop
else
{/*Netscape stuff*/}
percent=.1*(diffY-lastScrollY);
if(percent>0)percent=Math.ceil(percent);
else percent=Math.floor(percent);
document.getElementById("full").style.top=parseInt(document.getElementById("full").style.top)+percent+"px";
lastScrollY=lastScrollY+percent;
if(lastScrollY<200)
{
document.getElementById("full").style.display="none";
}
else
{
document.getElementById("full").style.display="block";
}
}
var gkuan=document.body.clientWidth;
var ks=(gkuan-960)/2-30;
suspendcode="<div id=\"full\" style='right:"+ks+"px;POSITION:absolute;TOP:200px;z-index:100;width:22px; height:58px;cursor:pointer;padding-top:25px; text-align:center; font-size:12px; line-height:14px; color:#4f576c;'><a onclick='window.scrollTo(0,0);'>返回顶部</a></div>"
document.write(suspendcode);
window.setInterval("heartBeat()",1);
</script>
追问
if(lastScrollY以上的代码,加进出貌似没什么用,我删了,还是可以用。
追答
if(lastScrollY以上的代码是测试用,用你自己的内容替换
window.setInterval("heartBeat()",1);把1调大到50左右,就慢了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询