Skip to content

Instantly share code, notes, and snippets.

View yuanhongboo's full-sized avatar
🎯
Focusing

yuanhongboo

🎯
Focusing
View GitHub Profile
export class {
/**
* 获取给定节点命中的 css 规则
* ---
* - 算法思路:
* - 获取沙箱环境中的全部样式规则
* - 过滤出匹配当前目标元素的样式规则
* - 计算样式规则权重,需要考虑的因子有:
* - 样式规则出现的先后顺序(难点:如何正确计算出样式规则出现的顺序?)
* - CSS 选择器权重计算规则:id > class/ > PShttps://gist.github.com/ssafejava/6605832
@yuanhongboo
yuanhongboo / mozGetMatchedCSSRules.js
Created April 6, 2022 05:25 — forked from darrnshn/mozGetMatchedCSSRules.js
A Blink only polyfill for Webkit's window.getMatchedCSSRules
// 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
@yuanhongboo
yuanhongboo / click move
Created October 12, 2021 02:00 — forked from zbo2018/click move
拖拽动作,不触发点击事件 拖动与点击事件冲突解决
拖动与点击事件冲突解决
问题:
有些用户的鼠标非常灵敏,点击的时候会偏移。出现轻微的拖拽操作
思路1:
点击到移动的时间间隔< 150ms: 点击事件
点击到移动的时间间隔>=150ms: 拖拽事件
解决办法:
mousedown时记录时间t1全局变量,
mousemove时记录时间t2局部变量,