Created
April 3, 2012 16:02
-
-
Save h4/2293181 to your computer and use it in GitHub Desktop.
Итог задания 05.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Анимированный блок</title> | |
<style> | |
#box { | |
height: 50px; | |
width: 100px; | |
background: #F00; | |
position: absolute; | |
left: 0; | |
} | |
</style> | |
<script> | |
function moveEl(el, direction) { | |
if (isNaN(parseInt(el.style.left))) { | |
el.style.left = 0; | |
} | |
if (parseInt(el.style.left) >= screen.availWidth - 100) { | |
clearInterval(t); | |
} else { | |
el.style.left = parseInt(el.style.left) + 10 + "px"; | |
} | |
} | |
window.onload = function() { | |
el = document.getElementById("box"); | |
t = setInterval(function() { moveEl(el); }, 100); | |
} | |
</script> | |
</head> | |
<body> | |
<div id="box"></div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Анимированный блок</title> | |
<style> | |
#box { | |
height: 50px; | |
width: 100px; | |
background: #F00; | |
position: absolute; | |
left: 0; | |
} | |
</style> | |
<script> | |
function moveEl(el, direction) { | |
if (typeof direction === 'undefined') { | |
direction = true; | |
} | |
if (isNaN(parseInt(el.style.left))) { | |
el.style.left = 0; | |
} | |
if (parseInt(el.style.left) >= screen.availWidth - 100) { | |
el.style.left = parseInt(el.style.left) - 10 + "px"; | |
clearInterval(t); | |
t = setInterval(function() {moveEl(el, !direction); }, 100); | |
} else if (parseInt(el.style.left) < 0) { | |
el.style.left = parseInt(el.style.left) + 10 + "px"; | |
clearInterval(t); | |
t = setInterval(function() {moveEl(el, !direction); }, 100); | |
} | |
else { | |
if (direction) { | |
el.style.left = parseInt(el.style.left) + 10 + "px"; | |
} else { | |
el.style.left = parseInt(el.style.left) - 10 + "px"; | |
} | |
} | |
} | |
window.onload = function() { | |
el = document.getElementById("box"); | |
t = setInterval(function() { moveEl(el); }, 100); | |
} | |
</script> | |
</head> | |
<body> | |
<div id="box"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment