我有一个函数可以增加 div 层位置的 css 质量,并且需要它在它达到一定数量的百分比时停止,无论是向右还是向左(取决于层)。我尝试使用大于运算符执行 if 语句,但似乎不起作用。这是完整的代码:
<html>
<head>
<title>Stelucir</title>
<style>
body {
background-color: white;
}
#bg-right {
background-color: black;
position: fixed;
top: 0;
bottom: 0;
left: 50%;
right: 0;
z-index: -1;
}
</style>
<script type="text/javascript">
var header = null; // object
var about = null; // object
var blog = null; // object
var forum = null; // object
var chat = null; // object
var home = null; // object
function doMove() {
header.style.right = parseInt(header.style.right)+1+'%';
about.style.left = parseInt(about.style.left)+1+'%';
blog.style.right = parseInt(blog.style.right)+1+'%';
forum.style.left = parseInt(forum.style.left)+1+'%';
chat.style.right = parseInt(chat.style.right)+1+'%';
home.style.left = parseInt(home.style.left)+1+'%';
setTimeout(doMove,30); // call doMove in 20msec
}
function init() {
header = document.getElementById('header');
about = document.getElementById('about');
blog = document.getElementById('blog');
forum = document.getElementById('forum');
chat = document.getElementById('chat');
home = document.getElementById('home');
doMove(); // start animating
}
window.onload = init;
</script>
</head>
<body>
<div id="bg-right"></div>
<div id="header" style = "position:absolute;right:25%;font-size:80px;">Stelucir</div>
<div id="about" style = "position:absolute;left:40%;font- size:40px;top:90px;color:white;">About</div>
<div id="blog" style = "position:absolute;right:40%;font-size:40px;top:130px;">Blog</div>
<div id="forum" style = "position:absolute;left:40%;font-size:40px;top:170px;color:white;">Forum</div>
<div id="chat" style = "position:absolute;right:40%;font-size:40px;top:210px;">Chat</div>
<div id="home" style = "position:absolute;left:40%;font-size:40px;top:250px;color:white;">Home</div>
</body>
</html>