function $(id) { return document.getElementById(id)};
function moves(){
var ypos = $("movebox").style.left;//这里为什么获取不到呢 使用parseInt也不行
alert(ypos);
if (ypos < 180) {
ypos++;
}
}
请指教 谢谢.
function moves(){
var ypos = $("movebox").style.left;//这里为什么获取不到呢 使用parseInt也不行
alert(ypos);
if (ypos < 180) {
ypos++;
}
}
请指教 谢谢.
难道需要先用脚本给它设定positon吗
一般是操作scroll
那个移动. 一般是操作外层的scroll来实现.. 因为这样的话. 就不用管那个DIV里是什么东西了.
function $(id) { return document.getElementById(id)};
function moves(){
var ypos = $("movebox").offsetLeft;//这里为什么获取不到呢 使用parseInt也不行
alert(ypos);
if (ypos < 180) {
ypos++;
}
$("movebox").style.left=ypos+"px";}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
.box{border:#C90 1px solid;width:200px;height:20px; margin:0 auto; overflow:hidden;}
.movebox{width:20px;height:20px; background:#9C0; overflow:hidden;}
</style>
</head><body onload="moves()">
<div class="box">
<div class="movebox" id="movebox"></div>
</div><script>
function $(id) { return document.getElementById(id)};
function moves(){
var ypos = $("movebox").offsetLeft; if (ypos < 180) {
ypos++;
}
$("movebox").style.left=ypos+"px";
setTimeout(moves,100)}</script>
</body>
</html>