This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class { | |
/** | |
* 获取给定节点命中的 css 规则 | |
* --- | |
* - 算法思路: | |
* - 获取沙箱环境中的全部样式规则 | |
* - 过滤出匹配当前目标元素的样式规则 | |
* - 计算样式规则权重,需要考虑的因子有: | |
* - 样式规则出现的先后顺序(难点:如何正确计算出样式规则出现的顺序?) | |
* - CSS 选择器权重计算规则:id > class/属性 > 标签(PS:https://gist.github.com/ssafejava/6605832) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// polyfill window.getMatchedCSSRules() in Chrome | |
if ( typeof window.getMatchedCSSRules !== 'function' ) { | |
var ELEMENT_RE = /[\w-]+/g, | |
ID_RE = /#[\w-]+/g, | |
CLASS_RE = /\.[\w-]+/g, | |
ATTR_RE = /\[[^\]]+\]/g, | |
// :not() pseudo-class does not add to specificity, but its content does as if it was outside it | |
PSEUDO_CLASSES_RE = /\:(?!not)[\w-]+(\(.*\))?/g, | |
PSEUDO_ELEMENTS_RE = /\:\:?(after|before|first-letter|first-line|selection)/g; | |
// convert an array-like object to array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
拖动与点击事件冲突解决 | |
问题: | |
有些用户的鼠标非常灵敏,点击的时候会偏移。出现轻微的拖拽操作 | |
思路1: | |
点击到移动的时间间隔< 150ms: 点击事件 | |
点击到移动的时间间隔>=150ms: 拖拽事件 | |
解决办法: | |
mousedown时记录时间t1全局变量, | |
mousemove时记录时间t2局部变量, |