如何让一个按钮在HTML中向下滚动页面? [英] How to make a button scroll down page in HTML?

查看:911
本文介绍了如何让一个按钮在HTML中向下滚动页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法在这里找到教程,或者没有使用正确的关键字。
我在制作一个单页网站,我想导航栏按钮向上/下滚动页面到右边的部分。
在HTML和CSS中这是可能的吗?

我对JavaScript没有这样的经验。

Couldn't find a tutorial for this anywhere or just didn't use the right keywords. I'm making a one-paged website, and I'd like the navigation bar buttons to scroll the page up/down to the right part. Would this be possible in just HTML and CSS?
I'm not so experienced with JavaScript.

类似于''Scroll

Similar to ''Scroll to the top'' but that I could decide to where it scrolls the page, like middle, top, bottom etc. .

推荐答案

更新:现在有了更好的方法来使用此功能,使用HTML id 属性:

Update: There is now a better way to use this, using the HTML id attribute:

设置目标ID:< h1 id =section1>第1节< / h1>

并使用锚标记创建指向该目的地的链接:< a href =#section1>转到第1部分

And create a link to that destination using the anchor tag: <a href="#section1">Go to section 1</a>

这种新方法的好处是可以在任何HTML元素上设置 id 属性。

The benefit of this new method is that the id attribute can be set on any HTML element. You don't have to wrap superfluous anchor tags around destination links anymore!

原始答案:

您可以查看使用HTML锚标签。

You can look at using the HTML anchor tag.

< a name =section1>第1节< / a>

< a href =#section1>前往第1节< / a>

当用户点击转到第1部分时,他们将被发送到页面中第1部分显示文本。

When the user clicks on "Go to section 1", they will be sent to the section of the page where the "Section 1" text is displayed.

这篇关于如何让一个按钮在HTML中向下滚动页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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