js 鼠标事件的位置x,y
摘要:1. clientX和clientY与x,y clientX和clientY与x,y一样的,都是客户当前显示的屏幕上(反之可能被卷去)可视区域坐标,指鼠标的坐标,以浏览器显示 网页 区域的左上角开始,x,y是新浏览器支持 2. offsetX,offsetY offsetX,offsetY 针对目标
阅读全文
js 修改当前的css
摘要:CSSStyleSheet.insertRule() CSSStyleSheet.insertRule(".red::before { color: lightgray;content:"测试" }",0) CSSStyleSheet.addRule() 已经移除废弃 stylesheet.dele
阅读全文
js dom className classList
摘要:classList dom.classList.contains('black') // 删除 black dom.classList.remove('black') // 新增.red dom.classList.add('red') className let cName = elementNo
阅读全文
js dom 类型判断
摘要:Node对象中的nodeName获取指定节点的节点名称(返回的是大写字母表示的) Node对象中的nodeType获取指定节点的节点类型 | 元素节点 | 属性节点 | 文本节点 | | | | | | 1 | 2 | 3 | Node对象中的nodeValue获取指定节点的值 详情见官网:http
阅读全文
js 获取上一个兄弟节点
摘要:previousSibling:获取元素的上一个兄弟节点;(既包含元素节点、文本节点、注释节点) previousElementSibling:获取上一个兄弟元素节点;(只包含元素节点) > 一般使用的都是这个
阅读全文
js 获取dom的绝对位置,相对于浏览器显示界面
摘要:// 获取左边 function getElementLeft(element){ var actualLeft = element.offsetLeft; var current = element.offsetParent; while (current !== null){ actualLef
阅读全文
css 防止鼠标拖动造成文字选中
摘要:body *{ -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select:
阅读全文
js mouse drag or click
摘要:onmousedown 鼠标按下触发事件 onmousemove 鼠标按下时持续触发事件 onmouseup 鼠标抬起触发事件 click点击事件=mouseup+mousedown drag拖拽=mousedown+mousemove+mouseup // 我们可以根据点击的位置、发生的事件或者时
阅读全文