研究调查问卷:请告诉我们您使用 Blockly 的体验
开始调查问卷
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
blockly > utils > dom
utils.dom 命名空间
枚举
Enumeration |
说明 |
NodeType |
节点类型常量:https://developer.mozilla.org/zh-CN/docs/Web/API/Node/nodeType |
Functions
函数 |
说明 |
addClass(element, className) |
向元素添加 CSS 类。 由于旧版原因,处理多个以空格分隔的类。 |
createSvgElement(name, attrs, opt_parent) |
用于创建 SVG 元素的辅助方法。 |
getFastTextWidth(textElement, fontSize, fontWeight, fontFamily) |
使用比 getTextWidth 更快的方法获取文本元素的宽度。此方法要求我们事先知道文本元素的字体系列和大小。与 getTextWidth 类似,我们会缓存所计算的宽度。 |
getFastTextWidthWithSizeString(textElement, fontSize, fontWeight, fontFamily) |
使用比 getTextWidth 更快的方法获取文本元素的宽度。此方法要求我们事先知道文本元素的字体系列和大小。与 getTextWidth 类似,我们会缓存所计算的宽度。此方法与 getFastTextWidth 类似,但要求字体大小参数为字符串。 |
getTextWidth(textElement) |
获取文本元素的宽度,并在进程中将其缓存。 |
hasClass(element, className) |
检查某个元素是否具有指定的 CSS 类。 |
insertAfter(newNode, refNode) |
在引用节点之后插入一个节点。与 node.insertBefore 函数相对。 |
measureFontMetrics(text, fontSize, fontWeight, fontFamily) |
测量字体的指标。高度和基线值。 |
removeClass(element, className) |
从元素中移除 CSS 类。 由于旧版原因,处理多个以空格分隔的类。 |
removeClasses(element, classNames) |
从元素中移除多个类。 |
removeNode(node) |
从其父节点中移除一个节点。如果未附加到父级,则无操作。 |
setCssTransform(element, transform) |
设置元素的 CSS transform 属性。此函数会设置不带供应商前缀和供应商前缀的版本,以便向后兼容旧版浏览器。请参阅 https://caniuse.com/#feat=transforms2d |
startTextWidthCache() |
开始缓存文本宽度。每次调用此函数时,还必须调用 stopTextWidthCache。缓存不得在执行线程之间保留下来。 |
stopTextWidthCache() |
停止缓存字段宽度。除非在对 startTextWidthCache 进行相应调用时已经启用缓存。 |
变量
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-05-20。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-05-20。"],[[["The `utils.dom` namespace provides helper functions for manipulating the Document Object Model (DOM), including elements and nodes."],["It offers functionalities for managing CSS classes, creating SVG elements, measuring text dimensions, and inserting/removing nodes."],["The namespace also includes utilities for working with CSS transforms and caching text width calculations for performance optimization."],["Constants and enumerations like `NodeType`, `HTML_NS`, `SVG_NS`, and `XLINK_NS` are provided for common DOM-related values."]]],["The `utils.dom` namespace provides tools for manipulating DOM elements. Key actions include adding and removing CSS classes (e.g., `addClass`, `removeClass`), creating SVG elements (`createSvgElement`), and inserting or removing nodes (`insertAfter`, `removeNode`). It also features functions for measuring text widths (`getTextWidth`, `getFastTextWidth`) and caching these measurements (`startTextWidthCache`, `stopTextWidthCache`). Additionally, it provides functions for setting CSS transforms and measuring font metrics, and defines namespaces for HTML, SVG, and XLINK elements.\n"]]