sollrei / mini-note Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://github.com/GcFETeam/10min-quick-share/issues
Home Page: https://github.com/GcFETeam/10min-quick-share/issues
width: 200px;
height: 300px;
background: url(https://picsum.photos/id/234/200/300);
background: -webkit-image-set(url(https://picsum.photos/id/234/200/300) 1x, url(https://picsum.photos/id/234/400/600) 2x);
background-size: cover;
在不同设备像素比下加载不同规格的图片
有点类似img的src-set
目前chrome支持需要写前缀
重置属性值为其继承到的或者用户代理设置的样式
目前基本只能在safari和firefox上看到效果
DEMO:
h3 {
font-weight: normal;
color: blue;
border-bottom: 1px solid grey;
}
<h3>This will have custom styles</h3>
<p>Just some text</p>
<h3 style="all: revert">This should be reverted to browser/user defaults</h3>
<p>Just some text</p>
.parent {
color: blue;
}
p {
color: red;
}
.alt {
color: revert;
}
<div class="parent">
<p>Lorem, ipsum dolor.</p>
<p class="alt">Fugit, id vel.</p>
</div>
图片
<input type="file" accept="image/*">
视频
<input type="file" accept="video/*">
音频
<input type="file" accept="audio/*">
摄像
<input type="file" accept="image/*" capture="camera">
录像
<input type="file" accept="video/*" capture="camera">
写accept=".jpg,.png"
可能出现“没有应用可执行操作”报错
mql = window.matchMedia(mediaQueryString)
返回MediaQueryList
对象,表示指定媒体查询字符串解析后的结果,对象的matches
属性表示是否匹配媒体查询
例
判断横竖屏
window.matchMedia("(orientation: portrait)").matches
orientation: portrait | landscape
portrait 高度大于等于宽度
判断移动设备
window.matchMedia('(max-device-width: 20em)').matches
监听查询变化
function handleOrientationChange(mql) {
if (mql.matches) {
// ...
} else {
// ...
}
}
var mql = window.matchMedia("(orientation: portrait)");
mql.addListener(handleOrientationChange);
handleOrientationChange(mql);
// 移除监听事件
mql.removeListener(handleOrientationChange);
兼容性 IE 10+
相关阅读:
https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Testing_media_queries
https://css-tricks.com/a-web-component-with-different-html-for-desktop-and-mobile/
* { box-sizing: border-box; }
.box {
position: relative;
filter: url('#colorMatrix'); /* 关键代码就这一行 */
height: 200px;
width: 200px;
}
span {
position: absolute;
right: 10px;
bottom: 10px;
height: 50px;
width: 50px;
border-radius: 50%;
text-align: center;
color: #fff;
line-height: 50px;
background: yellowgreen;
transition: transform .6s cubic-bezier(0.2,0,0.15,1);
}
.span1 { transition-delay: .1s; }
.span2 { transition-delay: .25s; }
.span3 { transition-delay: .4s; }
label {
position: absolute;
z-index: 10;
right: 10px;
bottom: 10px;
}
label span {
right: 0;
bottom: 0;
}
input:checked ~ .span1 {
transform: translate3d(-80px, 0, 0);
}
input:checked ~ .span2 {
transform: translate3d(-64px, -64px, 0);
}
input:checked ~ .span3 {
transform: translate3d(0, -80px, 0);
}
<div class="box">
<label for="input"><span><i class="fa fa-plus"></i></span></label>
<input type="checkbox" id="input" style="opacity: 0">
<span class="span1"><i class="fab fa-500px"></i></span>
<span class="span2"><i class="fab fa-facebook"></i></span>
<span class="span3"><i class="fab fa-twitter"></i></span>
</div>
<svg viewBox="0 0 200 200" width="200px" xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<filter id="colorMatrix">
<feGaussianBlur
in="SourceGraphic"
stdDeviation="7"
result="blur"
></feGaussianBlur>
<feColorMatrix
in="blur"
type="matrix"
values="1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 18 -7"
result="matrix"
>
</feColorMatrix>
<feBlend in="SourceGraphic" in2="matrix"></feBlend>
</filter>
</defs>
</svg>
feGaussianBlur高斯模糊滤镜
feColorMatrix是一个颜色矩阵计算,这儿相当于对原图形的每一个像素(Alpha透明度按0-1的值算):
1 0 0 0 0 // R = 1*R + 0*G + 0*B + 0*A + 0
0 1 0 0 0 // G = 0*R + 1*G + 0*B + 0*A + 0
0 0 1 0 0 // B = 0*R + 0*G + 1*B + 0*A + 0
0 0 0 18 -7 // A = 0*R + 0*G + 0*B + 18*A + (-7)
即RGB的值不变,修改了透明度通道的对比度
使用css也可以通过添加高斯模糊和提高对比度做类似的效果,但是相比还是svg效果更好一些
css的实现可以看这个 Shape Blobbing in CSS | CSS-Tricks
toLocaleString
numObj.toLocaleString([locales [, options]])
const money = 100000.12;
money.toLocaleString('zh', { style: 'currency', currency: 'CNY' });
// "¥1,000.12"
money.toLocaleString('zh', { style: 'currency', currency: 'CNY', currencyDisplay: 'code' });
// "CNY1,000.12"
money.toLocaleString('zh', { style: 'currency', currency: 'cny', currencyDisplay: 'name' });
// "1,000.12 人民币"
currency
货币符号,常用的例如CNY人民币,USD美元,JPY日元
currencyDisplay
格式化显示,symbol表示本地化的货币符号,code表示国际标准货币代码,name表示本地化货币名称
ES6 Intl
new Intl.NumberFormat([locales[, options]])
options部分和上面的类似
const money = 100000.12;
new Intl.NumberFormat('zh-CN', { style: 'currency', currency: 'CNY'}).format(money);
// "¥100,000.12"
然后简单写个时间的
const date = new Date();
new Intl.DateTimeFormat('zh-CN').format(date); // "2019/6/10"
date.toLocaleString('zh'); // "2019/6/10 上午9:07:06"
兼容性ie11+,两个都是 - -
参考:
Intl.NumberFormat - JavaScript | MDN
Number.prototype.toLocaleString() - JavaScript | MDN
想偷懒的话,toLocaleString 了解一下? – 酷辣虫 CoLaBug
Auto Rename TagHTML标签修改(重命名),vscode的改起始标签不会自动改结束标签,可以用这个插件实现
Bracket Pair Colorizer括号对高亮,方便查看代码块,可能影响到主题配色,不过可以自定义颜色和匹配的符号
IntelliSense for CSS, SCSS class names in HTML, Slim and SCSS,class智能命名,给出css文件或html文件中出现的class名称列表,也支持link引用的外部文件
代码格式化Prettier,之前没用eslint的时候感觉这个挺好用的,但是如果配置eslint保存自动修改可能会和它有一点冲突
Live Server,给页面开一个静态资源服务,并且支持实时更新,很方便很方便很方便
参考:
8 Useful VSCode Add-Ons New Front-end Developers Should Absolutely Download
.vscode/settings.json
{
"files.exclude": {
"dist": true
}
}
Object.fromEntries()
数组转对象
const myArray = [['one', 1], ['two', 2], ['three', 3]];
const obj = Object.fromEntries(myArray);
console.log(obj); // => {one: 1, two: 2, three: 3}
另外还有一个Object.entries()
(ES2017)是反过来的
const obj = {one: 1, two: 2, three: 3};
console.log(Object.entries(obj));
// => [["one", 1], ["two", 2], ["three", 3]]
trimStart() 和 trimEnd()
删除字符串开头、结尾空格
const str = " string ";
console.log(str.trimStart()); // => "string "
console.log(str.trimEnd()); // => " string"
flat() 和 flatMap()
扁平化嵌套数组
flat(path)
path用来指定深度
var arr1 = [1, 2, [3, 4]];
arr1.flat();
// [1, 2, 3, 4]
var arr2 = [1, 2, [3, 4, [5, 6]]];
arr2.flat();
// [1, 2, 3, 4, [5, 6]]
var arr3 = [1, 2, [3, 4, [5, 6]]];
arr3.flat(2);
// [1, 2, 3, 4, 5, 6]
flatMap()
类似先map一下再flat(1)
let arr = ["今天天气不错", "", "早上好"]
arr.map(s => s.split(""))
// [["今", "天", "天", "气", "不", "错"],[""],["早", "上", "好"]]
arr.flatMap(s => s.split(''));
// ["今", "天", "天", "气", "不", "错", "", "早", "上", "好"]
Symbol对象描述属性
let sym = Symbol(‘foo’);
console.log(sym.description); // => foo
sym = Symbol();
console.log(sym.description); // => undefined
// create a global symbol
sym = Symbol.for(‘bar’);
console.log(sym.description); // => bar
可选的catch绑定
try {
} catch {
}
参考:
5 ES2019 features you can use today
Array.prototype.flatMap()
var canvas = document.getElementById('canvas')
var ctx = canvas.getContext('2d')
var img = new Image;
img.setAttribute('crossOrigin', 'anonymous'); // 解决跨域问题 ie11+支持
img.src = 'https://img-i.gcimg.net/2019/1204/wk2buqe52kwboiza024634.png'
img.onload = function () {
ctx.drawImage(img, 0, 0);
var color = ctx.getImageData(1, 1, 1, 1).data;
var rgb = `rgb(${color[0]}, ${color[1]}, ${color[2]})`;
document.body.style.background = rgb;
}
.box {
width: 200px;
margin: 0 auto;
}
.multiple {
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
}
<div class="box">
<p class="multiple">层叠样式表(CSS)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。CSS不仅可以静态地修饰网页,还可以配合各种脚本语言动态地对网页各元素进行格式化。</p>
</div>
-webkit-line-clamp
属性可以限制块容器内容的行数,它仅在设置display
为-webkit-box
或者-webkit-line-box
并且-webkit-box-orient
属性值为vertical
时候才会生效
大部分情况下还需要设置overflow: hidden
,否则多余的行数不会被截取掉,但是依然会在限制的行末尾显示省略号
先放codepen地址Wrecking Ball
shape-outside
属性可以定义相邻内联元素围绕的形状。
以前做图文混排时图片浮动文字环绕在图周围,环绕的边界是矩形,利用这个属性可以定义圆形circle
,椭圆ellipse
,图片(环绕图片中的不透明部分),或者是其他几何形状polygon
,然后可以实现类似杂志中的炫酷排版,比如Art Direction For The Web Using CSS Shapes — Smashing Magazine
然后拐回去说那个动画:
@keyframes wreckit {
0% {
margin-left: -1000px;
shape-outside: circle( 150px at -850px 150px);
}
100% {
margin-left: 1000px;
shape-outside: circle( 150px at 1150px 150px);
}
}
这里使用了一个圆形,然后在左右移动中改变了圆的中心点坐标(半径 at 圆形x 圆心y),因为元素的margin-left值在改变,图形计算又是默认依据margin-box,如果不改圆心结果应该是这个样:
不过也可以改用其他盒模型,比如shape-outside: circle(100px) content-box;
:
话说为啥要分享这个动画……因为第一眼看到的时候觉得迷之搞笑😂
参考
标准:
shape-outside - CSS(层叠样式表) | MDN
文章:
Take A New Look At CSS Shapes — Smashing Magazine
It’s a trap-ezoid: CSS Shapes aren’t what you’dexpect
IntersectionObserver接口提供了目标元素(target)在根元素(root)中可视状态变化的监听方法。
可以用来更方便的实现类似图片懒加载,滚动加载更多,或者一些滚屏动画效果
先画一坨灰div
div*10{item}
if ('IntersectionObserver' in window) {
var observer = new IntersectionObserver(function (entries, _observer) {
entries.forEach(item => {
if (item.isIntersecting) { // 目标元素在根元素中可见(达到thresholds设置的范围)
item.target.style.background = '#517791'; // 执行一些啥啥操作,这里只是改了背景色
_observer.unobserve(item.target); // 取消观察
}
})
}, {
rootMargin: "0px 0px -60px 0px" // 监听元素和root边界的偏移量,类似css margin。这里值是距离底部60像素
// 这里还有两个可设置的属性:
// root: 指定根元素,需要是目标元素的祖先元素,默认是浏览器视窗(viewport)
// thresholds: 数组,值是监听元素和root边界交叉区域的比率
// 例如设置[0.3, 0.7],意味在交叉区域面积30%和70%的位置会执行回调函数
// 默认是0,即目标元素在root内一出现就会立即调用
});
document.querySelectorAll('div').forEach(item => { observer.observe(item) });
}
除了兼容性不太好没啥毛病
npm install font-spider -g
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
@font-face {
font-family: 'source';
src:
url('./font/SourceHanSerifCN-Heavy.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
* {
font-family: 'source';
}
</style>
</head>
<body>
这里是文字内容
</body>
</html>
font-spider index.html
原文:Create a responsive grid layout with no media queries, using CSS Grid - Andy Bell
html:
ul.auto-grid>li*12{Item $}
style:
grid-template-columns
定义网格列,auto-fill表示自动填充,单元格等宽并且宽度最小16rem,max值使用1fr会把剩余空间平分给每个item,它们会拉伸占满空间
/* grid */
.auto-grid {
--auto-grid-min-size: 16rem;
display: grid;
/* 网格列 */
grid-template-columns: repeat(auto-fill, minmax(var(--auto-grid-min-size), 1fr));
/* 网格间隔 */
grid-gap: 1rem;
}
/* ... 省略其他的一些样式 */
<div class="circle"></div>
.circle {
position: relative;
height: 100px;
width: 100px;
animation: circle .7s linear infinite;
border-radius: 50%;
/* 渐变圆圈 */
background:
radial-gradient(#fff, #fff 63%, transparent 64%),
linear-gradient(to top, #fa8807, #fff) 50px 0 no-repeat,
linear-gradient(to top, #fa8807, red) 0 0;
}
/* 旋转动画 */
@keyframes circle {
0% {
transform: rotate(0);
}
100% {
transform: rotate(360deg);
}
}
完整的css选择器列表: CSS4-Selectors | All selectors from level 4 to 1
需要用的还是先留意下浏览器兼容性😂
:required
和:optional
:required { color: red; } /* 带有required属性 */
:optional { color: blue; } /* 不带的 */
<input required type="text"> 红色文字
<input type="text"> 蓝色文字
:valid
和:invalid
:invalid { color: red; } /* 非法值 */
:valid { color: blue; } /* 合法值 */
<input required type="email">
填写邮箱蓝色,格式错误红色
:in-range
和:out-of-range
:out-of-range { color: red; } /* 指定区间外的值 */
:in-range { color: blue; } /* 指定区间内的值 */
<input type="number" value="2" max="4" min="0" step="1" />
0-4以外的值是红色,0-4蓝色
:placeholder-shown
:placeholder-shown { border: 1px solid red; }
<input placeholder="请输入" type="text">
没有输入内容时(placeholder显示)是红色边框
:indeterminate
:indeterminate { opacity: 0.6; }
/* checkbox 三种状态(checked, unchecked, indeterminate)中的 indeterminate(不确定) */
/* 也可用于radio 和 <progress> */
<label for="test">Label</label>
<input type="checkbox" id="test" />
<script>
// html中没 indeterminate="true" 这个属性,所以需要js设置
document.getElementById("test").indeterminate = true;
</script>
不知道为啥今天就突然想起来了这个东西……
使用DOMParser
将xml或html源码解析为DOM Document
const a = '<div class="div"><p>content</p></div>';
const parser = new DOMParser();
const doc = parser.parseFromString(a, 'text/html');
const result = doc.body.querySelector('.div');
document.body.appendChild(result);
用Range
对象的createContextualFragment
方法解析xml或html,返回文档片段DocumentFragment
const a = '<div class="div"><p>content</p></div>';
const result = document.createRange().createContextualFragment(a);
document.body.appendChild(result);
String.fromCharCode(Math.random() * 26 + 'a'.charCodeAt(0))
用于指定可替换元素(如img iframe等)适应到其宽高的方式,可取值fill | contain | cover | none | scale-down
img {
height: 100px;
width: 160px;
object-fit: contain;
}
效果类似于给背景图设置
background-size: contain
兼容性 IE (x)
:where() CSS 伪类函数接受选择器列表作为它的参数,将会选择所有能被该选择器列表中任何一条规则选中的元素。
:where() 的优先级总是为 0
阅读
https://css-tricks.com/using-the-specificity-of-where-as-a-css-reset/
nodejs返回413 (Request Entity Too Large) 解决方法:
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
app.use(bodyParser.json({limit: '50mb'}));
nginx需要修改nginx.conf文件,然后重启
http {
client_max_body_size 50M;
}
<img
src="https://picsum.photos/100/100?image=1"
srcset="https://picsum.photos/200/200?image=2 2x,
https://picsum.photos/300/300?image=3 3x"
>
根据不同的设备像素比使用不同尺寸的图得到更好的显示效果,一般可以用同一张图的三种尺寸,这里方便看用了不一样的图
chrome里有改像素比的设置
效果
<img
src="https://picsum.photos/300/300?image=3"
srcset="https://picsum.photos/300/300?image=3 300w,
https://picsum.photos/200/200?image=2 200w,
https://picsum.photos/100/100?image=1 100w"
sizes="(max-width: 300px) 100px, (max-width: 400px) 200px, 300px"
srcset里的w是图像固有宽度,sizes里的媒体查询后的值是图片要展示的尺寸(px,em,vw都可以);
展示的时候先找符合当前设备宽度的那个媒体查询条件,它后面值与上面srcset的哪个值最接近就用哪个图;
当然不支持的浏览器就会直接用src
例如现在是375px宽的设备,满足(max-width: 400px) 200px
就会使用200w的第二张图
但是如果设备像素比为2,图片实际使用尺寸是200*2,就会用400w的,但是这里没400w,就会用接近他的300w的那个
起手html你肯定猜到了是啥
<div id="editor" contentEditable></div>
然后是操作可编辑内容区域内容的API:
document.execCommand(aCommandName, aShowDefaultUI, aValueArgument)
aCommandName 命令名称
aShowDefaultUI 是否展示用户界面
aValueArgument 某些需要额外参数的命令的值
返回布尔值表示浏览器是否支持
demo:
简单的执行加粗
<button id="edit-bold">加粗</button>
const btn = document.getElementById('edit-bold');
btn.addEventListener('click', () => {
document.execCommand('bold', false, null);
}, false);
在可编辑的div内输入内容,选择后点击按钮就会有加粗效果。由于大部分标签在被点击的时候会让div失去焦点,所以要用button或者a标签比较好。
其他比如斜体,下划线,左、中、右对齐,创建列表等和这个类似。
在内容外添加标签需要用到第三个参数,例如标题和引用
document.execCommand('formatBlock', false, '<h1>');
修改字体,文字大小和颜色等类似,需要提供值的字符串作为参数。
具体命令列表参考
document.execCommand - Web API 接口参考 | MDN
阅读参考
富文本原理了解一下? - 掘金
const d = window.devicePixelRatio || 1;
const b = context.webkitBackingStorePixelRatio || 1;
const ratio = d / b;
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
let w = 400;
let h = 400;
canvas.style.width = w + 'px';
canvas.style.height = h + 'px';
canvas.width = w * ratio;
canvas.height = h * ratio;
ctx.scale(ratio, ratio);
.prettierrc.js
module.exports = {
// 加这一行
htmlWhitespaceSensitivity: "ignore"
}
感觉一些不错的文章,看完觉得还是基础不够扎实……补补课,之后也更新到这里
为什么 ‘1’, ‘7’, ’11’.map(parseInt) 返回 1, NaN, 3
示例地址 https://example.com/?product=shirt&color=blue&newuser&size=m
const queryString = window.location.search;
// ?product=shirt&color=blue&newuser&size=m
const urlParams = new URLSearchParams(queryString);
URLSearchParams IE不支持
const product = urlParams.get('product')
console.log(product);
// "shirt"
const newUser = urlParams.get('newuser')
console.log(newUser);
// ""
console.log(urlParams.has('product'));
// true
console.log(urlParams.has('paymentmethod'));
// false
console.log(urlParams.getAll('size'));
// [ 'm' ]
for (const key of urlParams.keys()) console.log(key);
// product, color, newuser, size
可以为元素后面区域添加filter效果,简单例子
@supports (-webkit-backdrop-filter: none) or (backdrop-filter: none) {
.modal {
-webkit-backdrop-filter: blur(10px);
backdrop-filter: blur(10px);
background-color: rgba(255, 255, 255, 0.5);
}
.warning {
display: none;
}
}
支持的浏览器就可以看到白色区域部分有模糊的效果;
另外为了能生效,元素或它的背景需要有部分透明
.modal { background-color: rgba(255, 255, 255, 0.95); }
目前支持的浏览器不是很多,可以更新下chrome感受感受
参考:
backdrop-filter - CSS(层叠样式表) | MDN
The backdrop-filter CSS property | CSS-Tricks
css tricks改版后的页面上看到的
<textPath>
通过xlink:href
引用<path>
元素,设置文字的排列;默认是沿着path的左侧(side=“right”
支持的浏览器比较少)
圆形路径的文字:
<svg height="200" width="200" viewBox="-100,-100,200,200">
<defs>
<path id="circle" d="M-100,0 A100,100,0 1 1 100,0 A100,100,0 1 1 -100,0Z"></path>
</defs>
<text>
<textPath xlink:href="#circle">text...</textPath>
</text>
</svg>
也能画些……乱七八糟的东西……
另外css tricks里还用到了自定义元素(custom element),定义<circle-text>
来封装圆形文字排版的效果,设置半径和旋转角度的属性,复用了svg部分的代码。具体的可以参考Circle Text Custom Element
顺便推荐绘制图形导出svg的软件:
Sketch
Affinity Designer
在线的Figma: the collaborative interface design tool.
其他:
- SVG: Scalable Vector Graphics | MDN
使用 custom elements - Web Components | MDN
<input type="tel" />
<input type=“number” pattern=“\d*” />
type="number"
会无视maxlength
,可以改用text
<input type="text" pattern=“\d*” />
原文: https://glennmccomb.com/articles/building-a-pure-css-animated-svg-spinner/
html
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<circle cx="50" cy="50" r="45"/>
</svg>
css
// SVG 样式.
svg {
max-width: 100px;
animation: 2s linear infinite svg-animation;
}
// Circle 样式.
circle {
animation: 1.4s ease-in-out infinite both circle-animation;
display: block;
fill: transparent;
stroke: #2f3d4c;
stroke-linecap: round;
stroke-dasharray: 283; // 圆周长
stroke-dashoffset: 280;
stroke-width: 10px;
transform-origin: 50% 50%;
}
包括三部分的动画
<circle>
元素stroke-dasharray
和 stroke-dashoffset
属性的值,实现的划线伸长变短的效果@keyframes circle-animation {
0%,
25% {
stroke-dashoffset: 280;
}
50%,
75% {
stroke-dashoffset: 75;
}
100% {
stroke-dashoffset: 280;
}
}
75%到100%旋转的地方划线是逆时针向后收缩变短的效果,由于circle顺时针旋转的比较快,看起来整体还是顺时针旋转
@keyframes circle-animation {
0%,
25% {
// ...
transform: rotate(0);
}
50%,
75% {
// ...
transform: rotate(45deg);
}
100% {
// ...
transform: rotate(360deg);
}
}
svg {
animation: 2s linear infinite svg-animation;
}
@keyframes svg-animation {
0% {
transform: rotateZ(0deg);
}
100% {
transform: rotateZ(360deg)
}
}
position sticky可以用来很方便的实现滚动粘滞效果,不需要判断滚动判断scrollTop一个属性搞定😂
.box {
position: sticky;
top: 10px; // 需要指定top right bottom left中的一个才会生效
}
效果相当于相对定位和固定定位的混合,在box到达顶部与父元素距离10像素之前为相对定位,之后就是固定定位。
推荐阅读
杀了个回马枪,还是说说position:sticky吧 « 张鑫旭-鑫空间-鑫生活
虽然兼容性
可以在支持的浏览器下使用,对其他做降级处理,其他常见的处理方式可以看这个
异步请求后端返回了多个文件下载地址
function downloadFile(url) {
const iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.style.height = 0;
iframe.src = url;
document.body.appendChild(iframe);
setTimeout(() => {
iframe.remove();
}, 1000);
}
文字方向设置为rtl后发现缺失括号,搜到的类似问题:
https://stackoverflow.com/questions/50467795/strange-behaviour-with-direction-rtl-and-closing-braces-at-the-end-of-the-sente
中的一个解决方式是添加‎
https://stackoverflow.com/questions/55276200/strange-chrome-behavior-in-rtl-with-parentheses
中提到的chrome 75解决了相关的渲染问题(可能是75出的新排版引擎layoutNG中优化了rtl的渲染效果)
image-rendering: auto | smooth | high-quality | crisp-edges | pixelated
设置图像缩放算法,指定图片缩小或者放大的情况下如何展示。
可以用于img元素,或者背景图和canvas中的图像。
借用w3c的栗子:
设置 auto | pixelated | crisp-edges 后“理想”的效果是:
chrome支持pixelated,firefox支持crisp-edges但是效果和pixelated差不多,参考Can I use。
pixelated很适合像素图,比如……二维码(左边设置pixelated, 右边正常)
更多:
sudo chown $USER ~/Library/Caches/com.microsoft.VSCode.ShipIt
<style>
.flex {
display: flex;
flex-wrap: wrap;
margin-bottom: 10px;
}
.item {
padding: 10px;
background-color: cornflowerblue;
}
.flex-col {
flex-direction: column;
align-items: flex-start;
align-content: flex-start;
height: 300px;
}
.break {
flex-basis: 100%;
width: 0;
height: 0;
}
</style>
<div class="flex">
<div class="item item1">1</div>
<div class="item item2">2</div>
<div class="item item3">3</div>
<div class="break"></div>
<div class="item item4">4</div>
<div class="item item5">5</div>
<div class="item item6">6</div>
<div class="item item7">7</div>
<div class="item item8">8</div>
</div>
<div class="flex flex-col">
<div class="item item1">1</div>
<div class="item item2">2</div>
<div class="item item3">3</div>
<div class="break"></div>
<div class="item item4">4</div>
<div class="item item5">5</div>
<div class="item item6">6</div>
<div class="item item7">7</div>
<div class="item item8">8</div>
</div>
<details>
<summary>title</summary>
<div class="content">content...</div>
</details>
<details>
有一个open属性(表示内容部分是否可见的布尔值)和toggle事件(可见状态改变触发),它的默认的样式
details和summary可以用来实现一些常用的折叠展开效果,例如手风琴,折叠菜单,下拉菜单(栗子看这个页面右上角)
这里利用了
open
属性和before
伪元素,添加了一个点击菜单外的关闭效果
甚至是做个弹窗
GitHub - github/details-dialog-element
关于默认样式中的小箭头样式,标准方法是改list-style
(试了下firfox可以),chrome中可以用summary::-webkit-details-marker
修改
summary::-webkit-details-marker {
background: url(right-arrow.svg);
color: transparent;
}
关于浏览器支持:反正用Chromium的Edge是要支持了😂……
Can I use… Support tables for HTML5, CSS3, etc
阅读更多:
借助HTML5 details,summary无JS实现各种交互效果 « 张鑫旭-鑫空间-鑫生活
Quick Reminder that Details/Summary is the Easiest Way Ever to Make an Accordion | CSS-Tricks
<div class="pie-chart"></div>
.pie-chart {
border-radius: 100%;
width: 300px;
height: 300px;
background-image: conic-gradient(#f66 0 25%, #66f 25% 30%, #f90 30% 55%, #09f 55% 70%, #3c9 70% 100%);
}
超简单有木有真的超简单有木有除了兼容性不好真的超简单有木有
conic-gradient和radial-gradient:
https://developer.mozilla.org/zh-CN/docs/Web/CSS/conic-gradient
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.