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
/** | |
* Provides requestAnimationFrame in a cross browser way. | |
* @author paulirish / http://paulirish.com/ | |
*/ | |
if ( !window.requestAnimationFrame ) { | |
window.requestAnimationFrame = ( function() { | |
return window.webkitRequestAnimationFrame || |
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
/** Get parameter after query(ex:?p=1) sign. | |
* @param {string} parameter name. | |
*/ | |
var GetURLParameter = function(sParam){ | |
var oPageURL = window.location.href; | |
var sPageURL = oPageURL.split('?')[1]; | |
if(sPageURL == null){ | |
return; | |
} | |
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 target_date = new Date("Aug 6, 2015").getTime(); | |
// variables for time units | |
var days, hours, minutes, seconds; | |
function updateCountdown(){ | |
// get current time stampe | |
var current_date = new Date().getTime(); | |
// get seconds by using target_date - current_date, divide by million second. | |
var seconds_left = (target_date - current_date) / 1000; |
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 versions = function (){ | |
var u = navigator.userAgent, app = navigator.appVersion; | |
var ua = navigator.userAgent.toLowerCase(); | |
return { //偵測移動端瀏覽器版本信息 | |
trident: u.indexOf('Trident') > -1, //IE 核心 | |
presto: u.indexOf('Presto') > -1, //opera 核心 | |
webKit: u.indexOf('AppleWebKit') > -1, //Apple, google 核心 | |
gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //Firefox 核心 | |
mobile: !!u.match(/AppleWebKit.*Mobile.*/), //行動裝置 |
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
// 10 可以更換成為其他數字(例: .{.20} 即為每20個字元換行) | |
// 以下例子是以每10個字元換行 | |
string.replace(/(.{10})/g, "$1\n"); | |
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
function AddZeroDigitsBefore(d, digits){ | |
var nStr = d + ''; | |
var digits = digits || 0; | |
while(nStr.length < digits){ | |
nStr = '0' + nStr; | |
} | |
return nStr; | |
} |
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
function randomRGBColor(){ | |
var r = Math.floor(Math.random()*256); | |
var g = Math.floor(Math.random()*256); | |
var b = Math.floor(Math.random()*256); | |
return "rgb("+ r + "," + g + "," + b +")"; | |
} | |
function randomHSLColor(){ | |
var h = Math.floor(Math.random()*360); |
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
/** | |
* Fix the 'ie' is not compatible with window.scrollY | |
* test with ie 9, 10, 11, edge. | |
**/ | |
function getScrollTop(){ | |
var t = typeof window.scrollY === 'undefined' ? window.pageYOffset : window.scrollY; | |
return t; | |
} |
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
function getCanvasMousePosition(e, canvas) { | |
var isRetina = true; | |
var offsetX = 0, offsetY = 0, mx, my; | |
if (canvas.offsetParent !== undefined) { | |
do { | |
offsetX += canvas.offsetLeft - canvas.scrollLeft; | |
offsetY += canvas.offsetTop - canvas.scrollTop; | |
} while ((canvas = canvas.offsetParent)); | |
} |
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
// Converts from degrees to radians. | |
Math.radians = function(degrees) { | |
return degrees * Math.PI / 180; | |
}; | |
// Converts from radians to degrees. | |
Math.degrees = function(radians) { | |
return radians * 180 / Math.PI; | |
}; |
OlderNewer