【发布时间】:2012-05-01 20:45:52
【问题描述】:
我有一个函数可以增加 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>
【问题讨论】:
-
if声明在哪里? -
我说我试过了但没用,我没有说我将它包含在代码中,我提到的是为了保存我已经尝试过的东西的建议。
-
嗯,
if声明几乎肯定会涉及。包含您尝试过但不起作用的内容通常很有用,以便人们可以解释如何解决它。
标签: javascript animation settimeout