只使用CSS / HTML平滑滚动到页面顶部? [英] Smooth scroll to top of page with CSS/HTML only?

查看:175
本文介绍了只使用CSS / HTML平滑滚动到页面顶部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不允许在此网站中添加Jquery / Javascript,所以我一直在寻找任何方法来实现返回顶部按钮,并且只通过CSS / HTML过渡到顶端。我认为这是可能的,但检查是否有人遇到了解决方案。 解决方案

它不会是一个平滑的滚动,但你可以使用achor标签链接到页面的任何部分。这里是W3学校的一个例子。

 <!DOCTYPE html> 
< html>
< body>

< h2>< a id =top>页面底部有一个链接!< / a>< / h2>

< p>在我更年轻,更脆弱的年代,父亲给了我一些建议,从那以后我一直在思考着什么。< / p>
< p>每当你想批评任何人时,他告诉我,只要记住,这个世界上的所有人都没有你有过的优点。< / p>
< p>他没有再说什么,但我们一直以保留的方式异常交流,我明白他的意思远不止于此。因此,我倾向于保留所有的判断,这种习惯为我打开了许多奇特的天性,也使我成为不少经验丰富的窟窿的受害者。当异常心灵出现在一个正常的人身上时,这种异常的心灵很快就会发现并附加在这个质量上,所以在大学里我被不公正地指责为一个政治家,因为我了解了野外,未知的秘密悲伤男子。当我意识到一个明确的启示即将在地平线上颤动时,我大部分的信心都是不合时宜的 - 我经常假装睡觉,专注,或者有敌意的轻快。对于年轻人的亲密启示,或者至少是他们表达他们的条款,通常是剽窃和明显的压制。保留判断是一个无限希望的问题。如果我忘记了这一点,我仍然有点害怕,正如我的父亲势利的建议,并且我势利地重复一遍,一种基本的礼节感在出生时就被不平等地分配了。< / p>
< p>在夸耀了我的宽容之后,我承认它有一个限制。行为可能建立在坚硬的岩石或潮湿的沼泽地上,但在某一点之后,我不在乎它建立在什么基础上。去年秋天,当我从东方回来的时候,我觉得我希望这个世界能够统一,并且永远受到一种道德上的关注。我希望不会再有特别的瞥见进入人心。只有给这本书起名的人盖茨比免于我的反应 - 盖茨比,他代表了我不受任何蔑视的一切。如果人格是一系列成功的姿态,那么他就会有一些华丽的东西,一些人对生活的承诺敏感得多,好像他和那些能够记录一万英里外的地震的复杂机器中的一个有关系。这种反应性与那种以创造性气质为名的威严的印象性无关 - 这是对希望的非凡礼物,是一种浪漫的准备,如我从未在任何其他人身上发现过的那种浪漫的准备,我将再次找到。没有盖茨比在最后显得很好;正是在盖茨比身上发现了什么,在他的梦中浮现出什么污点,这些尘埃暂时地关闭了我对失败的悲伤和男人的短暂兴奋的兴趣。< / p>

< a href =#top>转到页首< / a>
< / body>
< / html>

基本上,href使用css选择器来决定要去哪个锚点



更新:因此,我在平滑滚动认为我会在这个问题上发布它。


I am not permitted to add in Jquery/Javascript to this site, so I was looking for any way to do a "Back to Top" button, and have it transition to top with CSS/HTML only....don't think it's possible, but checking to see if anyone has come across a solution.

解决方案

It wont be a smooth scroll but u can use an achor tag to link to any part of the page. Here is an example from W3 schools.

<!DOCTYPE html>
<html>
<body>

<h2><a id="top">There is a link at the bottom of the page!</a></h2>

<p>In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since.</p>
<p>"Whenever you feel like criticizing any one," he told me, "just remember that all the people in this world haven't had the advantages that you've had."</p>
<p>He didn't say any more, but we've always been unusually communicative in a reserved way, and I understood that he meant a great deal more than that. In consequence, I'm inclined to reserve all judgments, a habit that has opened up many curious natures to me and also made me the victim of not a few veteran bores. The abnormal mind is quick to detect and attach itself to this quality when it appears in a normal person, and so it came about that in college I was unjustly accused of being a politician, because I was privy to the secret griefs of wild, unknown men. Most of the confidences were unsought-frequently I have feigned sleep, preoccupation, or a hostile levity when I realized by some unmistakable sign that an intimate revelation was quivering on the horizon; for the intimate revelations of young men, or at least the terms in which they express them, are usually plagiaristic and marred by obvious suppressions. Reserving judgments is a matter of infinite hope. I am still a little afraid of missing something if I forget that, as my father snobbishly suggested, and I snobbishly repeat, a sense of the fundamental decencies is parcelled out unequally at birth.</p>
<p>And, after boasting this way of my tolerance, I come to the admission that it has a limit. Conduct may be founded on the hard rock or the wet marshes, but after a certain point I don't care what it's founded on. When I came back from the East last autumn I felt that I wanted the world to be in uniform and at a sort of moral attention forever; I wanted no more riotous excursions with privileged glimpses into the human heart. Only Gatsby, the man who gives his name to this book, was exempt from my reaction-Gatsby, who represented everything for which I have an unaffected scorn. If personality is an unbroken series of successful gestures, then there was something gorgeous about him, some heightened sensitivity to the promises of life, as if he were related to one of those intricate machines that register earthquakes ten thousand miles away. This responsiveness had nothing to do with that flabby impressionability which is dignified under the name of the "creative temperament"-it was an extraordinary gift for hope, a romantic readiness such as I have never found in any other person and which it is not likely I shall ever find again. No-Gatsby turned out all right at the end; it is what preyed on Gatsby, what foul dust floated in the wake of his dreams that temporarily closed out my interest in the abortive sorrows and short-winded elations of men.</p>

<a href="#top">Go to top</a>
</body>
</html>

basically the href uses a css selector to decide which anchor to go to

UPDATE: So I found an interesting link on smooth scrolling thought I would post it on this question.

这篇关于只使用CSS / HTML平滑滚动到页面顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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