为了账号安全,请及时绑定邮箱和手机立即绑定

问一下这个错在哪?麻烦大神看下

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title></title>

<style type="text/css">

#div1{

width:200px;

height:200px;

border:2px solid red;

position:absolute;

left:0px;

top:0px;

}

</style>

<script type="text/javascript">

function startqwe(){

var qwe=document.getElementById('div1');

function moveqwe(){

qwe.style.left=qwe.style.offsetLeft+10+'px';

}

setInterval(moveqwe(),30);

}

</script>

</head>

<body>

<div id="div1"></div>

<input type="button" value="点击开始运动" onclick="startqwe()" />

</body>

</html>


正在回答

2 回答

#div1{
width:200px;
height:200px;
border:2px solid red;
position:absolute;
left:0px;
top:0px;
}
加个z-index:-1;

qwe.style.left=qwe.style.offsetLeft+10+'px';
改成
qwe.style.left=qwe.offsetLeft+10+'px';


0 回复 有任何疑惑可以回复我~
#1

死之外科医生 提问者

我记得之前学css的时候z-index是元素堆叠顺序的表示这里加这个是为什么了?
2017-03-30 回复 有任何疑惑可以回复我~
#2

死之外科医生 提问者

好吧我懂了谢谢大神
2017-03-30 回复 有任何疑惑可以回复我~
#3

死之外科医生 提问者

非常感谢!
2017-03-30 回复 有任何疑惑可以回复我~

<script type="text/javascript">

function startqwe(){

var qwe=document.getElementById('div1');

qwe.style.left=qwe.offsetLeft+10+'px';

alert(qwe.style.left);

setInterval(startqwe,100);

//此处不能写startqwe();

}

</script>


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
JS动画效果
  • 参与学习       113937    人
  • 解答问题       1443    个

通过本课程JS动画的学习,从简单动画开始,逐步深入各种动画框架封装

进入课程

问一下这个错在哪?麻烦大神看下

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信