refugee
پنج شنبه 28 دی 1391, 14:33 عصر
سلام یک دایو دارم میخواهم وقتی رو پلی کلیک شد حرکت کنه و و قتی استپ شد واسته ./
کد ها رو نوشتم و همه جی کامله ولی فقط مقدار اولیه رو تکرار میکنه و جلو تر نمیره . من میخواهم تا اخر صفحه سمت راست حرکت کنه ...
ممنون میشم ببینید و کمکم کنید .
//javascript code
var box;
var anim;
function play(){
box = document.getElementById ("box");
if(box.style.left == undefined) box.style.left = '0px';
anim = setInterval (animation,100);
}
function animation(){
box.style.left = ((+box.style.left)+10)+"px";
console.log(box.style.left);
if ((+box.style.left)>=window.innerWidth-box.clientWidth)
stop();
}
function stop(){
clearInterval (anim);
}
<!DOCTYPE html>
<html>
<head>
<title>Go To Right</title>
<script type="text/javascript" src="goright.js"></script>
</head>
<body>
<button onclick="play()">Play</button>
<button onclick="stop()">Stop</button>
<div id="box" style="background-color:#333; width:100px; height:100px;position:absolute"></div>
</body>
</html>
کد ها رو نوشتم و همه جی کامله ولی فقط مقدار اولیه رو تکرار میکنه و جلو تر نمیره . من میخواهم تا اخر صفحه سمت راست حرکت کنه ...
ممنون میشم ببینید و کمکم کنید .
//javascript code
var box;
var anim;
function play(){
box = document.getElementById ("box");
if(box.style.left == undefined) box.style.left = '0px';
anim = setInterval (animation,100);
}
function animation(){
box.style.left = ((+box.style.left)+10)+"px";
console.log(box.style.left);
if ((+box.style.left)>=window.innerWidth-box.clientWidth)
stop();
}
function stop(){
clearInterval (anim);
}
<!DOCTYPE html>
<html>
<head>
<title>Go To Right</title>
<script type="text/javascript" src="goright.js"></script>
</head>
<body>
<button onclick="play()">Play</button>
<button onclick="stop()">Stop</button>
<div id="box" style="background-color:#333; width:100px; height:100px;position:absolute"></div>
</body>
</html>