【发布时间】:2026-02-03 05:05:02
【问题描述】:
我有两个 div:
width:100%; height:100%
所以我的整个文档的高度为 200%; 两个 div 都有一个相互链接,
现在当我点击链接时,我希望网站顺利滑到另一个 div,
我知道这将如何在 jquery 中工作,例如使用 .scrollto,但我的客户想要一个没有框架的应用程序。只有 javascricpt 和 css!
我尝试使用 translateY 来实现它,但没有成功!
这是一个示例代码: http://jsfiddle.net/hSU7R/
HTML
<div class="full" id="one">
<span style="width:100%; background-color:blue">
<a href="#two" >Scroll to 2</a>
</span>
</div>
<div class="full" id="two">
<span style="width:100%; background-color:blue">
<a href="#one" >Scroll to 1</a></span>
</div>
CSS
html,body {
width:100%;
height:100%;}
.full {
height:100%;
width:100%;}
#one {background-color:green}
#two {background-color:red}
【问题讨论】:
-
代码的基本介绍也将欢迎您的帖子...
-
此链接可能会有所帮助:w3schools.com/jsref/prop_win_pagexoffset.asp
-
允许CSS3还是需要支持IE8及以下?
-
@Aaron 请不要链接到 w3Schools,只有可以适应的地方是不好的做法和无效的代码:(.
-
@Teemu jsfiddle.net/hSU7R 是基本介绍!
标签: javascript html css css-transitions