- 元素整体缩放,大小不变;
width: 125%;
transform: scale(0.8);
- 获取文本宽度方法:
function getTextWidth2(text, fontSize, fontWeight = 'normal', family = 'sans-serif') {
const _span = document.createElement('span');
_span.style.position = 'absolute';
_span.style.visibility = 'hidden';
_span.style.fontSize = fontSize + 'px';
_span.style.fontWeight = fontWeight;
_span.innerText = text;
document.body.appendChild(_span);
let width = _span.offsetWidth;
document.body.removeChild(_span);
return width
}
function getTextWidth(text, fontSize = 12, fontWeight = 'normal', family = 'sans-serif') {
if(getTextWidth.canvas) {
getTextWidth.canvas = null
}
getTextWidth.canvas = document.createElement("canvas")
var ctx = getTextWidth.canvas.getContext("2d");
ctx.font = 'bold ' + fontSize + 'px' + family;
var metrics = ctx.measureText(text);
return metrics.width;
}
- 修改Chrome、Firfox浏览器默认滚动条样式
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-button {
display: none;
}
::-webkit-scrollbar-thumb {
border-radius: 4px;
background-color: #ddd;
cursor: pointer;
}
::-webkit-scrollbar-thumb:hover {
cursor: pointer;
background-color: rgb(210, 210, 210);
}
::-webkit-scrollbar-track {
border-radius: 4px;
background-color: white;
}
scrollbar-color: #ddd white;
scrollbar-width: thin;
- 动画库
- 抖动效果库:CSShake, 地址: https://elrumordelaluz.github.io/csshake/