有没有办法滚动来锚定而不是使用javascript跳转(类似于平滑滚动) [英] Is there way to scroll to anchor rather than jump with javascript (something like smooth scroll)

查看:72
本文介绍了有没有办法滚动来锚定而不是使用javascript跳转(类似于平滑滚动)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有编号锚标签的大型文档,如下所示.还有一个文本框,用于使用 window.location.hash

I have a large document with numbered anchor tags as shown below. And a textbox to punch the numbers in to go to anchor which uses window.location.hash

我还使用箭头键转到下一个或上一个锚点.我想滚动到锚点,以便提供方向感.

I am also using arrow keys to go next or previous anchors. I want to scroll to the anchor so to give some sense of direction.

<a name="1">
some text
<a name="2">
some text
<a name="3">

这是我的功能

function updatePageNumber()
{
    var pagenumber;
    pagenumber = document.getElementById('pageNumber').value;   
    window.location.hash =  pagenumber;
}

跳转到锚非常丑陋,人们在文本中失去了方向感.因此,有没有一种方法可以滚动以锚定JavaScript.我知道有很多jQuery示例,但我不知道jQuery,也找不到JavaScript.

Jumping to anchor is very ugly and people loose sense of direction in the text. So is there a way to scroll to anchor with JavaScript. I know there are lots of jQuery examples, but I don't know jQuery and couldn't find JavaScript.

最重要的原因是我想在地址栏上看到我的页码!

Most important reason is I want to see my page number on the address bar!

推荐答案

平滑的滚动演示

使用JavaScript创建平滑滚动效果

这篇关于有没有办法滚动来锚定而不是使用javascript跳转(类似于平滑滚动)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆