Js双击空白页面返回顶部

nimaboke 2016-2-12 3081

这也就是js页面滚动代码,但我找了很久也没找出来,后来用了论坛的双击向下滚动页面代码做了修改才实现的
[code lang="js"]
<script language="JavaScript" type="text/JavaScript">
//双击鼠标滚动屏幕的代码
var currentpos,timer;
function initialize()
{
timer=setInterval ("scrollwindow ()",30);
}
function sc()
{
clearInterval(timer);
}
function scrollwindow()
{
currentpos=document.body.scrollTop;
window.scroll(0,++currentpos);
if (currentpos !=document.body.scrollTop)
sc();
}
document.onmousedown=sc
document.ondblclick=initialize
</script>
[/code]
这是双击向下滚动的,改成相反的就能双击向上滚动
[code lang="js"]
var currentpos,timer;
function initialize()
{
timer=setInterval ("scrollwindow ()",1);
}
function sc()
{
clearInterval(timer);
}
function scrollwindow()
{
currentpos=document.body.scrollTop;
window.scroll(0,--currentpos);
if (currentpos !=document.body.scrollTop)
sc();
}
document.onmousedown=sc
document.ondblclick=initialize
[/code]
将滚动去除,变成直接返回顶部
[code lang="js"]
var currentpos,timer;
function initialize()
{
timer=setInterval ("scrollwindow ()",1);
}
function sc()
{
clearInterval(timer);
}
function scrollwindow()
{
currentpos=document.body.scrollTop;
window.scroll(0,-currentpos);
if (currentpos !=document.body.scrollTop)
sc();
}
document.onmousedown=sc
document.ondblclick=initialize
[/code]
具体效果可以在本站空白页面双击实现
最新回复 (0)