You Don't Know the Hack tech in the frontend development

你所不知道的前端黑科技

css in js animation

https://www.ifchange.com/

live demo

See the Pen css in js 黑科技 by xgqfrms
(@xgqfrms) on CodePen.

js hover/over event

https://www.ifchange.com/about#done

onmouseover

https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseover_event

// 单行写一个评级组件
let rate = 1;
"★★★★★☆☆☆☆☆".slice(5 - rate, 10 - rate);
// "★☆☆☆☆"

JavaScript 错误处理

// JavaScript Error & StackOverflow

const log = console.log;

try {
// throw new Error(`ts`);// ts
const err = {
type: "ts",
message: "ts error",
};
// throw new Error(err);
throw new Error(JSON.stringify(err));
} catch (e) {
log(e, typeof e, e.message)
// Error: {"type":"ts","message":"ts error"}
// "object" "{"type":"ts","message":"ts error"}"
const obj = JSON.parse(e.message)
log(obj)
const {
type,
message,
} = obj;
window.parent.location.href = `https://stackoverflow.com/search?q=[${type}]+${message}`;
}
// JavaScript Error & StackOverflow

const log = console.log;

try {
const err = {
type: "ts",
message: "ts error",
};
throw new Error(JSON.stringify(err));
} catch (e) {
// log(e, typeof e, e.message)
const {
type,
message,
} = JSON.parse(e.message);
window.parent.location.href = `https://stackoverflow.com/search?q=[${type}]+${message}`;
}

CSS 黑科技

UI 结构检测,加 1px 边框

// UI 结构检测,加 1px 边框

[].forEach.call($$("*"), function(a){
a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16)
}) // OR
Array.prototype.forEach.call(document.querySelectorAll('*'), dom => dom.style.outline = `1px solid #${parseInt(Math.random() * Math.pow(2,24)).toString(16)}`);
void 0 === undefined
// true
Array(6).fill(8)

//  (6) [8, 8, 8, 8, 8, 8]

// 金融数字格式化
// 1234567890 --> 1,234,567,890 // 正则实现 const test1 = '1234567890'
const format = test.replace(/\B(?=(\d{3})+(?!\d))/g, ','); console.log(format);
// 1,234,567,890 // 非正则实现 function formatCash(str) {
return str.split('').reverse().reduce((prev, next, index) => {
return ((index % 3) ? next : (next + ',')) + prev
})
} console.log(formatCash('1234567890'));
// 1,234,567,890

refs

https://juejin.im/entry/5998f8396fb9a0247c6ec9cd


xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


You Don't Know the Hack tech in the frontend development的更多相关文章

  1. (转) [it-ebooks]电子书列表

    [it-ebooks]电子书列表   [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Obj ...

  2. Frontend Development

    原文链接: https://github.com/dypsilon/frontend-dev-bookmarks Frontend Development Looking for something ...

  3. RednaxelaFX写的文章/回答的导航帖

    https://www.zhihu.com/people/rednaxelafx/answers http://hllvm.group.iteye.com/group/topic/44381#post ...

  4. 【转】Styling And Animating SVGs With CSS

    原文转自:http://www.smashingmagazine.com/2014/11/03/styling-and-animating-svgs-with-css/?utm_source=CSS- ...

  5. Top JavaScript Frameworks, Libraries & Tools and When to Use Them

    It seems almost every other week there is a new JavaScript library taking the web community by storm ...

  6. GitHub awesome Resource

    各种Awesome技术资源的资源聚合: https://github.com/sindresorhus/awesome Contents Platforms Programming Languages ...

  7. frontend-tools

    收集整理好用的前端开发利器(Collect good front-end development tools ) 1.w3cplus前端工具 2.jsfiddle在线JS代码调试工具 3.w3cfun ...

  8. 所有语言的Awesome(2)

    Curated list of awesome lists https://awesomeweekly.co https://github.com/sindresorhus/awesome ✨ Pre ...

  9. Tech Stuff - Mobile Browser ID (User-Agent) Strings

    Tech Stuff - Mobile Browser ID (User-Agent) Strings The non-mobile stuff is here (hint: you get jerk ...

随机推荐

  1. LOJ10077

    题目描述给出一个 N 个顶点 M 条边的无向无权图,顶点编号为 1∼N.问从顶点 1 开始,到其他每个点的最短路有几条. 输入格式第一行包含 2 个正整数 N,M,为图的顶点数与边数. 接下来 M行, ...

  2. 安装Archlinux+UEFI启动

    为了安装Arch自己也走了很多弯路,找了很多教程,最后探索出了这样一个安装方法,不一定适用于每个人. ArchWiki官方安装手册 本方法全程插上网线. 准备 获取镜像 镜像可以从官网获取,访问官方下 ...

  3. 如何在windows下切换node版本

    安装nvm 最近的项目中,一个是用vue项目开发,一个是使用react开发,但是ant design pro使用了umi框架,所需要的node版本>10.0.0,vue那个项目中又不兼容node ...

  4. Java 性能调优的 11 个实用技巧

    大多数开发人员认为性能优化是个比较复杂的问题,需要大量的经验和知识.是的,这并不没有错.诚然,优化应用程序以获得最好的性能并不是一件容易的事情,但这并不意味着你在没有获得这些经验和知识之前就不能做任何 ...

  5. Django(自定义过滤器和自定义标签)

    模版是一个用django模版语言标记过的python字符串.模版可以包含模版标签和变量. 模版标签是在一个模版里起作用的标记.比如,一个模版标签可以产生控制结构的内容(if或者for),可以获取数据库 ...

  6. 21.iptables

    1.策略与规则链 iptables 服务把用于处理或过滤流量的策略条目称之为规则,多条规则可以组成一个规则链,而规则链则依据数据包处理位置的不同进行分类,具体如下: 在进行路由选择前处理数据包(PRE ...

  7. 如何使用命令将文件夹中的文件名(包括路径)写入到txt文件中

    在cmd中使用 cd /d 路径,进入当前文件夹中 使用 dir /s /b > 0.txt 如图:

  8. Codeforces Round #675 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1422 A. Fence 题意 给出三条边 $a,b,c$,构造第四条边使得四者可以围成一个四边形. 题解 $d = max( ...

  9. Equal Numbers Gym - 101612E 思维

    题意: 给你n个数vi,你有k次操作.每一次操作你可以从n个数里面挑一个数,然后使得这个数乘于一个正整数.操作完之后,这n个数里面不同数的数量就是权值.你要使得这个值尽可能小. 题解: 如果a%b== ...

  10. hdu5432Rikka with Array (数位dp+十进制转化为二进制)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...