Skip to content

Instantly share code, notes, and snippets.

View jokemmy's full-sized avatar
😏
Working for my life!

Zhenyu.Xu jokemmy

😏
Working for my life!
View GitHub Profile
@jokemmy
jokemmy / app-cant-open.md
Last active February 2, 2019 09:13
mac系统 应用程序 xxx 不能打开 的解决方法
$ chown -R <$whoami>:admin xxx.app # 这个可以不要
$ chmod -R 775 xxx.app
@jokemmy
jokemmy / node-error.md
Last active January 14, 2019 06:33
node install error

Unexpected end of JSON input while parsing near

npm cache clean --force
sudo spctl --master-disable
@jokemmy
jokemmy / 148句古诗.txt
Created May 18, 2018 06:22
背下这148句古诗词,你可提高一个层次,不止在文学方面
1、知我者,谓我心忧,不知我者,谓我何求。(诗经王风黍离)
——了解我心情的人,认为我心中惆怅;不了解我心情的,还以为我呆在这儿有什么要求呢!
2、人而无仪,不死何为。(诗经风相鼠)
——为人却没有道德,不死还有什么意思。(如果做人可以不讲究仪表,那还不如死了呢!
3、言者无罪,闻者足戒。(诗经大序)
// 驼峰转连词符
const hyphenateRE = /([a-z\d])([A-Z])/g;
export function hyphenate( str ) {
return str.replace( hyphenateRE, '$1-$2' ).toLowerCase();
}
// 连词符转成驼峰
const camelCaseRE = /-(\w)/g;
@jokemmy
jokemmy / requestAnimationFrame-polyfill.js
Last active May 10, 2018 08:47
只是记录一下代码,其实现在的浏览器环境已经完全不用写 setTimeout 兼容了
import is from 'whatitis';
import now from 'performance-now';
const root = typeof window === 'undefined' ? global : window;
const vendors = [ 'moz', 'webkit' ];
const suffix = 'AnimationFrame';
let raf = root[`request${suffix}`];
let caf = root[`cancel${suffix}`] || root[`cancelRequest${suffix}`];

动画实现原则

在实现动画时,我个人一直遵循以下几个原则:

  1. 性能,性能,还是性能:这方面的建议就是在有选择时,一定要使用基于CSS的动画,将JS作为备选,因为考虑到硬件加速和性能之后,CSS几乎总是优于原生JS实现的动画
  2. 微小低调的动画往往表现更好
  3. 大而绚丽的动画需要带有目的性:不能只为了“好看”
  4. 动画持续时间要短
  5. 让动画具有弹性:或者说缓动效果
  6. 动画不要突然停止
body {
text-align: center;
}
img {
max-width: 100%;
width: 600px;
}
img {
@jokemmy
jokemmy / 防止拦截window.open.txt
Created January 9, 2018 07:02
防止拦截 window.open
window.open是javascript函数,该函数的作用是打开一个新窗口或这改变原来的窗口,如果你直接在js中调用window.open()函数去打开一个新窗口,浏览器会拦截你,那么如何避免呢。
注意,只有直接使用js调用 window.open(url); 打开新窗口时,才会被拦截,如果是改变原理额窗口:window.open(url,'_self'); 则不会被拦截。
那么 js调用 window.open(url); 打开新窗口,如何才能不会浏览器拦截呢?
浏览器会拦截你,是认为你将弹出广告等用户不想得到的窗体,所以如果不想让浏览器拦截你,你可以将这个函数改为用户点击时触发,这样浏览器就认为是用户想访问这个页面,而不是你直接弹出给用户。
0)最好的解决方法:
@jokemmy
jokemmy / FileSaver.js
Created January 9, 2018 05:49
前端文件保存
/* FileSaver.js
* A saveAs() FileSaver implementation.
* 1.3.2
* 2016-06-16 18:25:19
*
* By Eli Grey, http://eligrey.com
* License: MIT
* See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
*/