Created
December 11, 2014 05:52
-
-
Save fukajun/09b782443bfe8b6d3c4a to your computer and use it in GitHub Desktop.
This file contains 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
<html> | |
<body> | |
</body> | |
<script> | |
function num(px) { | |
return Number(px.replace('px', '')) | |
} | |
function px(num) { | |
return num + "px"; | |
} | |
function move(el) { | |
setInterval(function(){ | |
el.style.top = num(el.style.top) + 10 | |
el.style.left += num(el.style.left) + 10 | |
}, 30) | |
} | |
function intRandom(n) { | |
return Math.floor(Math.random() * n) | |
} | |
function createSnow() { | |
var startLeft = px(intRandom(1000) % 1000) | |
var snow = document.createElement('img'); | |
snow.src = "https://www.google.co.jp" | |
snow.style.backgroundColor= "black"; | |
snow.style.position = "absolute" | |
snow.style.width = "20px" | |
snow.style.height = "20px" | |
snow.style.top = "10px" | |
snow.style.left = startLeft | |
document.body.appendChild(snow); | |
return snow | |
} | |
for(var i = 0; i < 100; i++) { | |
var s = null | |
setTimeout(function(){ | |
s = createSnow(); | |
move(s) | |
}, intRandom(20000)) | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment