写了一段原生JS的运动效果,但是我换成了jQuery写就不行了,控制台也报错,提示未定义,高人指点下,谢谢
<head><styletype="text/css">*{padding:0;margin:0;}#div1{width:100px;height:100px;back...
<head>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
#div1{
width: 100px;
height: 100px;
background: red;
left: 0;
top: 50px;
position: absolute;
}
</style>
<script type="text/javascript" src="jquery-1.11.3.min.js"></script>
<script>
window.onload=function(){
var sport = document.getElementById('div1');
var ck = document.getElementById('btn');
var timer = null;
ck.onclick=function(){
timer=setInterval(function(){
if(sport.offsetLeft == 300){
clearInterval(timer);
}else{
sport.style.left=sport.offsetLeft+10+'px';
}
},30);
}
}
</script>
</head>
<body>
<button id="btn">点击开始运动</button>
<div id="div1"></div>
</body>
以下代码是原生写的代码 展开
<style type="text/css">
*{
padding: 0;
margin: 0;
}
#div1{
width: 100px;
height: 100px;
background: red;
left: 0;
top: 50px;
position: absolute;
}
</style>
<script type="text/javascript" src="jquery-1.11.3.min.js"></script>
<script>
window.onload=function(){
var sport = document.getElementById('div1');
var ck = document.getElementById('btn');
var timer = null;
ck.onclick=function(){
timer=setInterval(function(){
if(sport.offsetLeft == 300){
clearInterval(timer);
}else{
sport.style.left=sport.offsetLeft+10+'px';
}
},30);
}
}
</script>
</head>
<body>
<button id="btn">点击开始运动</button>
<div id="div1"></div>
</body>
以下代码是原生写的代码 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询