演示:http://jsfiddle.net/DerekL/8ZLTc/
This is <div>
<h3 class="front">FRONT</h3>
<h3 class="back">BACK</h3>
</div>.
h3 {
position: absolute;
margin: 0;
padding: 0;
color: #ff4056;
cursor: pointer;
}
div {
position: relative;
display: inline-block;
width: 170px;
height: 50px;
margin: 0;
padding: 0;
}
.front {
z-index: 2;
}
body > * {
vertical-align: text-bottom;
}
*建议的 JavaScript:(Transit.js 用于提高可读性。还有 jQuery。)
$(".back").css({
rotateX: '-180deg'
});
var words = [
"useful", "interesting", "lorem", "ipsum",
"stack", "overflow", "easter", "eggs"],
angle = 0;
setInterval(function (){
angle += 180;
$('div').transition({
perspective: '150px',
rotateX: '+=180deg'
}, 1000);
var currentB = "." + ((angle / 180) % 2 ? "front" : "back"),
current = "." + ((angle / 180) % 2 ? "back" : "front");
$(current).html(words[(Math.random() * 8) | 0]);
$("div").transition({
width: $(current).width(),
height: $(".front").height()
});
}, 1000);
这适用于所有现代浏览器,except IE.