这大致近似于您那里的代码,显然正如其他人所说,这仅适用于现代浏览器 - 我不建议纯粹使用这个系统 - 但它可以作为渐进增强工作,如战争10ck。
http://jsfiddle.net/3VQ9X/
有关其工作原理以及需要注意的问题的更多信息,请阅读以下链接:
这是涉及的标记和CSS。
标记
<div id="wrapper">
<nav>
<h3><a href="#content-1">App 1</a><h3>
<h3><a href="#content-2">App 2</a><h3>
</nav>
<section class="main">
<section class="box-content" id="content-1">
<p> This is content 1 </p>
</section>
<section class="box-content" id="content-2">
<p> This is content 2 </p>
</section>
</section>
</div>
css(基本元素设置,可以随意修改)
nav {
border: 1px solid black;
float: left;
}
section.main {
position: relative; /* this is important */
overflow: hidden; /* as is this, but everthing else can be modified */
float: left;
border: 1px solid red;
width: 500px; /* having fixed dimensions will make things easier */
height: 500px;
}
css(魔法位)
section.box-content {
position: absolute;
left: 0;
top: 0;
-webkit-transition: all 1.0s ease-in-out;
-moz-transition: all 1.0s ease-in-out;
-ms-transition: all 1.0s ease-in-out;
-o-transition: all 1.0s ease-in-out;
transition: all 1.0s ease-in-out;
-webkit-transform: translate(0,-500px);
-moz-transform: translate(0,-500px);
-ms-transform: translate(0,-500px);
-o-transform: translate(0,-500px);
transform: translate(0,-500px);
}
/* the pseudo selector :target only comes into effect when
an anchored link has been clicked that targets a specific
element by id. If the element with the id has this pseudo
selector applied, then the css will be applied. Tie this
together with transformations, and you have interactive
dynamic css :) */
section.box-content:target {
-webkit-transform: translate(0,0);
-moz-transform: translate(0,0);
-ms-transform: translate(0,0);
-o-transform: translate(0,0);
transform: translate(0,0);
}