1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <!DOCTYPE html> <html> <head> ... </head> <body> <div id='wrapper'> <!-- Toast...................................................--> <div id='toast'></div> ... </div> ... </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 | #toast { position: absolute; ... -webkit-transition: opacity 0.5s; -moz-transition: opacity 0.5s; -o-transition: opacity 0.5s; transition: opacity 0.5s; opacity: 0; z-index: 1; display: none; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | var SnailBait = function () { ... this.toast = document.getElementById('toast'), this.DEFAULT_TOAST_TIME = 3000, // 3 seconds ... }; SnailBait.prototype = { ... start: function () { ... snailBait.splashToast('Good Luck!'); }, splashToast: function (text, howLong) { howLong = howLong || this.DEFAULT_TOAST_TIME; toast.style.display = 'block'; toast.innerHTML = text; setTimeout( function (e) { toast.style.opacity = 1.0; // After toast is displayed }, 50); setTimeout( function (e) { toast.style.opacity = 0; // Starts CSS3 transition setTimeout( function (e) { toast.style.display = 'none'; // Just before CSS3 animation concludes }, 480); }, howLong); }, ... } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | var SnailBait = function (canvasId) { ... this.toast = document.getElementById('toast'), }; window.onblur = function (e) { // Pause if unpaused if (!snailBait.paused) { snailBait.togglePaused(); } }; window.onfocus = function (e) { // unpause if paused var originalFont = snailBait.toast.style.fontSize; if (snailBait.paused) { snailBait.toast.style.font = '128px fantasy'; snailBait.splashToast('3', 500); // Display 3 for one half second setTimeout(function (e) { snailBait.splashToast('2', 500); // Display 2 for one half second setTimeout(function (e) { snailBait.splashToast('1', 500); // Display 1 for one half second setTimeout(function (e) { snailBait.togglePaused(); setTimeout(function (e) { // Wait for '1' to disappear snailBait.toast.style.fontSize = originalFont; }, 2000); }, 1000); }, 1000); }, 1000); } }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | var SnailBait = function (canvasId) { ... this.windowHasFocus = true, ... }; ... SnailBait.prototype = { ... splashToast: function (text, howLong) { howLong = howLong || this.DEFAULT_TOAST_TIME; toast.style.display = 'block'; toast.innerHTML = text; setTimeout( function (e) { if (snailBait.windowHasFocus) { toast.style.opacity = 1.0; // After toast is displayed } }, 50); setTimeout( function (e) { if (snailBait.windowHasFocus) { toast.style.opacity = 0; // Starts CSS3 transition } setTimeout( function (e) { if (snailBait.windowHasFocus) { toast.style.display = 'none'; } }, 480); }, howLong); }, ... }; ... window.onblur = function (e) { // pause if unpaused snailBait.windowHasFocus = false; if (!snailBait.paused) { snailBait.togglePaused(); } }; window.onfocus = function (e) { // unpause if paused var originalFont = snailBait.toast.style.fontSize; snailBait.windowHasFocus = true; if (snailBait.paused) { snailBait.toast.style.font = '128px fantasy'; snailBait.splashToast('3', 500); // Display 3 for one half second setTimeout(function (e) { snailBait.splashToast('2', 500); // Display 2 for one half second setTimeout(function (e) { snailBait.splashToast('1', 500); // Display 1 for one half second setTimeout(function (e) { if ( snailBait.windowHasFocus) { snailBait.togglePaused(); } setTimeout(function (e) { // Wait for '1' to disappear snailBait.toast.style.fontSize = originalFont; }, 2000); }, 1000); }, 1000); }, 1000); } }; |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |