Skip to content

Instantly share code, notes, and snippets.

@if540
if540 / zeroDisplay
Created September 15, 2020 03:29
去零
/**
* 去零
* @param {number} value 輸入
* @param {number} position 小數點第 N 位
*/
function zeroDisplay (value, position = 2) {
let number = value * 1
return isNaN(number) ? 0 : parseFloat(number.toFixed(position))
}
@if540
if540 / toPointFixed.js
Created September 15, 2020 03:28
取小數點第 N 位
/**
* 取小數點第 N 位
* @summary 末位四捨五入
* @param {number} value 輸入
* @param {number} position 小數點第 N 位
*/
function toPointFixed (value, position) {
const decimalType = 10
let decimalNumber = Math.pow(decimalType, position)
return Math.round(value * decimalNumber) / decimalNumber
@if540
if540 / vuePluginTemp
Last active July 8, 2020 03:54
vue js plugin component template for install code
import Radio from './Radio'
import Gropu from './Group'
Radio.Gropu = Gropu
Radio.install = function(Vue) {
Vue.component(Radio.name, Radio
Vue.component(Radio.Group.name, Radio.Group)
}
@if540
if540 / deepFlatten.js
Last active May 30, 2020 00:50
Deep flattens an array.
const deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v)));
// deepFlatten([1, [2], [[3], 4], 5]); // [1,2,3,4,5]
@if540
if540 / isPassive.js
Created April 24, 2019 06:43
iscroll 被動事件偵聽器以提升滾動性能(ie not support)
/**
* iscroll 被動事件偵聽器以提升滾動性能(ie not support)
* source code : https://github.com/cubiq/iscroll/blob/master/demos/demoUtils.js
* MDN : https://developer.mozilla.org/zh-CN/docs/Web/API/EventTarget/addEventListener#option%E6%94%AF%E6%8C%81%E7%9A%84%E5%AE%89%E5%85%A8%E6%A3%80%E6%B5%8B
* passive google article : https://developers.google.com/web/tools/lighthouse/audits/passive-event-listeners?hl=zh-tw
*/
function isPassive () {
var passiveSupported = false
try {
@if540
if540 / toUTC.js
Created April 10, 2019 02:34
時間格式轉換
// 1554863406354 to Wed Apr 10 2019 10:29:26 GMT+0800 (台北標準時間)
function toUTC (value) {
var date = new Date()
if (value) {
date = new Date(value)
}
var nowUtc = Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(),
date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds())
return nowUtc
@if540
if540 / Bookmark
Last active August 29, 2019 05:24
學習書籤
git 教
- https://github.com/mylxsw/growing-up/blob/master/doc/%E7%A0%94%E5%8F%91%E5%9B%A2%E9%98%9FGIT%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B%E6%96%B0%E4%BA%BA%E5%AD%A6%E4%B9%A0%E6%8C%87%E5%8D%97.md
- https://kingofamani.gitbooks.io/git-teach/content/chapter_3_branch/git.html
C# https://docs.microsoft.com/zh-tw/dotnet/csharp/language-reference/keywords/enum
canvas flash 分層 - https://www.ibm.com/developerworks/cn/web/wa-canvashtml5layering/index.html
UIUX class - https://xue.uisdc.com/ixd/
@if540
if540 / detectDevice.js
Created January 18, 2019 04:58
檢測設備顯示特徵(Detecting the Device's Display Characteristics)
// 檢試是否為行動裝置
function isMobile() {
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
retrun true
} else {
return false
}
}
@if540
if540 / toPointFixed.js
Last active January 17, 2019 06:15
去小數點 ( Math.floor 向下取值 )
function toPointFixed(value, position) {
const decimalType = 10;
let decimalNumber = Math.pow(decimalType, position)
return Math.floor(value * decimalNumber) / decimalNumber
}
@if540
if540 / _cssTable.sass
Last active January 21, 2020 19:31
css table (Bem style)
/* cssTable */
.c-cssTable
display: table
+has(thead)
display: table-header-group
+has(tbody)
display: table-row-group