1、object-fit 属性
object-fit:contain 图像将调整大小以适应其容器的纵横比,如果图像的纵横比与容器不匹配它将被拉黑
object-fit:fill 图像将被调整大小以适应其容器的纵横比,如果图像的纵横比与容器不匹配它将被挤压或拉伸
object-fit:cover:图像将被调整大小以适应其容器的纵横比,如果图像的纵横比与容器的不匹配那么它将被裁剪以适应
2、数组内字符串的排序方法
localeCompare
a.localCompare(b)-升序
b.localCompare(a)-降序
3、在html中添加判断语句
<!-- 判断是后期修改加上的 -->
{{if data[0].pic}}
<img src="{{ data[0].pic }}" οnerrοr="this.classList.add('error');"/>
{{/if}}
{{if data[0].title}}
<div class="detail js_limit_text">
<a title="{{data[0].title_no_tag}}" href="{{ data[0].url }}" target="_blank" >
<span class="js_text line_clamp_two">{{@ data[0].title}}</span>
</a>
</div>
{{/if}}
4、js中宏任务和微任务
原型链的顶层指向空、宏任务、微任务
js的事件分为两种:宏任务和微任务
宏任务:script、setTimeout、setInterval、setImmediate、IO操作、UI交互事件、postMessage
微任务:promise.then/catch/finally、process.nextTick(Node.js环境)、MutaionOberver(浏览器环境)、Object.observe
先执行宏任务再执行微任务,先同步再异步
5、用/分隔取指定下标的值
data.parentColumn = data.parentColumn.substring(data.parentColumn.lastIndexOf("/",data.parentColumn.lastIndexOf("/")-1)+1,data.parentColumn.lastIndexOf("/"))
6、.使用动画样式实现防抖节流的代码
throttle {
animation: throttle 1s step-end forwards;
}
.throttle:active {
animation: none;
}
@keyframes throttle {
from {
pointer-events: none;
}
to {
pointer-events: all;
}
}
7、用Math.max获取数组中的最大值的方法
Math.max.apply(Math,arr)
8、z-index 在何种情况下生效
只有当元素的position为:relative,absolute,fixed等脱离了文档流的定位时,z-index才会生效。