Skip to content

Instantly share code, notes, and snippets.

View ntnyq's full-sized avatar
🐣
Learning rust

ntnyq ntnyq

🐣
Learning rust
View GitHub Profile
@ntnyq
ntnyq / detect-img-light.js
Created September 29, 2018 11:43
检测图片的明暗度。
/* This function will convert each color to gray scale and return average of all pixels, so final value will be between 0 (darkest) and 255 (brightest) */
function getImageLightness(imageSrc,callback) {
var img = document.createElement("img");
img.src = imageSrc;
img.style.display = "none";
document.body.appendChild(img);
var colorSum = 0;
img.onload = function() {
@ntnyq
ntnyq / deepMerge.js
Last active September 6, 2019 09:46
Merge object deeply
const deepMerge = (target = {}, origin = {}) => {
const toString = Object.prototype.toString;
for (let prop in origin) {
let originProp = origin[prop],
targetProp = target[prop];
if (typeof originProp === 'object') {
if (toString.call(originProp) === '[object Object]') {
target[prop] = {};
@ntnyq
ntnyq / location_size.js
Last active September 6, 2019 10:01
[Get location and size] #JavaScript
// 元素的偏移量 只读属性
// 包含了元素在屏幕上占的所有可用空间 由元素的大小来决定 包括内边距边框和滚动条
// !!! 不包括外边距
// 元素的offsetTop和offsetLeft属性是到上级包含它的元素的距离
// 计算元素在页面上的偏移量 将偏移量循环到根元素即可得到
function getOffsetPos (element) {
var offsetTop = element.offsetTop,
offsetLeft = element.offsetLeft;
@ntnyq
ntnyq / os-fonts.md
Last active September 6, 2019 09:50
[Font-family settings] #CSS

实例

  • 例1(小米米官网):font: 14px/1.5 "Helvetica Neue",Helvetica,Arial,"Microsoft Yahei","Hiragino Sans GB","Heiti SC","WenQuanYi Micro Hei",sans-serif;
  • 例2(淘宝技术研发中心):font: 12px/1.5 tahoma,arial,'Hiragino Sans GB','\5b8b\4f53',sans-serif;
  • 例3(加网 ):font: 14px/1.5 'Microsoft YaHei',arial,tahoma,\5b8b\4f53,sans-serif;
  • 例4(淘宝UED):font: 12px/1 Tahoma,Helvetica,Arial,"\5b8b\4f53",sans-serif;
  • 例5(一淘UX):font-family: Helvetica, 'Hiragino Sans GB', 'Microsoft Yahei', '微软雅黑', Arial, sans-serif;
  • 例6(简书):font-family: "lucida grande", "lucida sans unicode", lucida, helvetica, "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;

HTML,CSS,font-family:中文字体的英文名称

通用

@ntnyq
ntnyq / gradient.scss
Last active September 6, 2019 10:00
[SCSS utils] #Utils #SCSS
// 背景色
background: linear-gradient(45deg,#00ae7b,#0081bf); // 蓝绿色渐变
/* 文字 */
// 黄色
background-image: linear-gradient(to bottom, #fffffd 15%, #ffff0b 60%);
@ntnyq
ntnyq / og-twitter.html
Last active September 6, 2019 10:00
[HTML meta tags] #HTML
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@ntnyq">
<meta name="twitter:title" content="">
<meta name="twitter:description" content="">
<meta name="twitter:image" content="">
<meta property="og:image" content="" itemprop="thumbnailUrl">
<meta property="og:title" content="">
<meta property="og:url" content="">
<meta property="og:site_name" content="">
<meta property="og:description" content="">
@ntnyq
ntnyq / singleton.js
Created October 17, 2018 06:00
单例模式
var ntnyq = function () {
function Goy () {}
Goy.fn = Goy.prototype;
return new Goy();
}();
@ntnyq
ntnyq / jquery-back2top.js
Last active September 6, 2019 09:51
[Jqery Utils] #jQuery #Utils
;(function ($) {
var $backToTop = $('#back-to-top');
$(window).scroll(function(e) {
if ($(window).scrollTop() >= 100) {
$backToTop.fadeIn(300);
} else {
$backToTop.fadeOut(300);
}
});
$backToTop.click(function(e) {
@ntnyq
ntnyq / eventEmitter.js
Created October 17, 2018 06:33
仿Vue的EventEmitter实现
var EventEmiter = function (){
this._events = {};
};
EventEmiter.prototype.on = function (event, cb){
if (Array.isArray(event)){
for (let i = 0, l = event.length; i < l; i++){
this.on(event[i], cb);
}
} else {
@ntnyq
ntnyq / require.context.js
Last active September 6, 2019 09:59
[Webpack tricks] #Webpack
const files = require.context('.', true, /models\/[^/]+\.js$/)
files.keys().forEach(key => {
module.exports[key.replace(/\.\/models\/|\.js/g, '')] = files(key).default
})