防抖和节流
摘要:防抖 当事件被触发时,设定一个周期延迟执行动作,若期间又被触发,则重新设定周期,直到周期结束,执行动作 function debounce(func, delay) { let timer = null; return function (...arguments) { clearTimeout(t
阅读全文
insert-text-at-cursor-in-a-content-editable-div
摘要:https://stackoverflow.com/questions/2920150/insert-text-at-cursor-in-a-content-editable-div function insertTextAtCaret(text) { var sel, range; if (win
阅读全文
Constant width to height ratio
摘要:<div class="constant-width-to-height-ratio"></div> .constant-width-to-height-ratio { background: #9C27B0; width: 50%; } .constant-width-to-height-rati
阅读全文
async/await error
摘要:function smartPromise(promise){ return promise.then(res=>([null,res])).catch((e)=>([e,null])); } async function task(){ const [errorA,fileA] = await s
阅读全文
JS精准运算
摘要:function accAdd(arg1, arg2) { var r1, r2, m; try { r1 = arg1.toString().split(".")[1].length; } catch (e) { r1 = 0; } try { r2 = arg2.toString().split
阅读全文
手写JS
摘要:取整 var a = ~~2.33 //(四舍五入) var b= 2.55 | 0//上取整 var c= 2.33 >> 0//下取整 金钱格式化:1234567890 --> 1,234,567,890 var test1 = '1234567890' var format = test1.r
阅读全文
js groupBy
摘要:function groupBy( array , id ) { let groups = {}; array.forEach( function( o ) { let group = JSON.stringify( o[id] ); groups[group] = groups[group] ||
阅读全文
js rand(min, max)
摘要:rand(min, max) { return parseInt(Math.random() * (max - min + 1) + min, 10); },
阅读全文
h5 video
摘要:<div class="relative"> <video class="w-full h-full object-fill" id="ckplayer_a1" :src="url" x5-video-player-type="h5" preload="metadata" playsinline="
阅读全文
微信 分享
摘要:var link = location.href $.ajax({ url: 'your_url', //后台给你提供的接口 type: 'GET', data: { url: link }, async: true, dataType: 'json', success: function(data
阅读全文
tailwind + vue
摘要:在根目录下生成 tailwind 配置文件 npx tailwind init --full 修改 package.json 的 postcss 选项 "postcss": { "plugins": { "tailwindcss": "./tailwind.config.js", "autoprefixer": {} } }, ...
阅读全文
baidu jsonp
摘要:var s = "https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=132&json=1"; var fetchJsonp = function(url){ var body = document.getElementsByTagName('body')[0]; //插入一个s...
阅读全文
template string
摘要:let name = 'Bar' let template = ` ${name} `.trim();
阅读全文
faker image
摘要:http://placehold.it http://placekitten.com/g/200/300 带文字 https://placeholdit.imgix.net/~text?txtsize=50&txt=logo&w=110&h=110&txttrack=0 cat http://pla
阅读全文
truncate
摘要:css php blade @truncate($card->title, 20)
阅读全文