AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

owner

简介

owner 是 Yuka js 库中提供的一个实用工具,用于获取 DOM 元素的所有者文档对象。在某些情况下,文档对象可能不是当前文档,而是元素嵌套的另一个 iframe 内的文档对象。

使用方法

使用 owner 函数获取元素的所有者文档对象,语法如下:

const ownerDoc = owner(element);

其中,element 为要获取文档对象的 DOM 元素。

示例

在以下示例中,我们将获取嵌套在 iframe 中的 div 元素的所有者文档对象。

<!DOCTYPE html>
<html>
<head>
  <title>嵌套文档示例</title>
</head>
<body>
  <iframe src="http://example.com" frameborder="0"></iframe>
  <script src="yuka.js"></script>
  <script>
    const iframe = document.querySelector('iframe');
    const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
    const div = iframeDoc.createElement('div');
    iframeDoc.body.appendChild(div);

    const ownerDoc = Yuka.owner(div);
    console.log(ownerDoc);
  </script>
</body>
</html>

在该示例中,我们创建了一个 iframe 元素,并将其 src 设置为外部网站的地址。接着,我们获取 iframe 元素的文档对象,并创建了一个 div 元素,将其添加到 iframe 文档的 body 元素中。最后,我们使用 owner 函数获取 div 元素的所有者文档对象,并将其输出到控制台中。

注意事项

  • owner 函数返回的是文档对象。
  • 如果元素不在任何文档中,owner 函数返回 null。