Created
June 21, 2012 12:07
-
-
Save ww24/2965407 to your computer and use it in GitHub Desktop.
瞬きっぽいものの実装(Googleのトップページで動きます)
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
// 通常の画像 | |
var normal = "https://www.google.co.jp/logos/classicplus.png"; | |
// 瞬き画像 | |
var blink = "https://www.google.com/images/srpr/logo3w.png"; | |
// 瞬きさせる画像のidを指定 | |
var elem = document.getElementById("hplogo"); | |
// Google logo | |
var set = function (url) {elem.src = url}; | |
if (elem.src !== normal) { | |
set = function (url) {elem.style.background = "url(" + url + ") no-repeat"} | |
set(normal); | |
} | |
// 2秒毎に3割の確率80ミリ秒間画像が変わります(瞬きします) | |
setInterval(function () { | |
if (Math.random() * 10 < 3) { | |
set(blink); | |
setTimeout(function () { | |
set(normal); | |
}, 80); | |
} | |
}, 2000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment