【发布时间】:2015-02-18 20:41:18
【问题描述】:
我正在尝试在 div 上使用 core-animation 来为其位置设置动画。为此,我必须使用 document.getElementById() 选择它。 问题是,我的 index.html 文件中有一个相当复杂的结构,我找不到选择该 div 的方法。
这里是 index.html 结构(我需要选择#el):http://i.imgur.com/phWyArO.jpg
我的 index.html 文件:
<template is="auto-binding" id="t">
<!-- Route controller. -->
<flatiron-director route="{{route}}" autoHash></flatiron-director>
<!-- Keyboard nav controller. -->
<core-a11y-keys id="keys" target="{{parentElement}}"
keys="up down left right space space+shift"
on-keys-pressed="{{keyHandler}}"></core-a11y-keys>
<core-header-panel>
<core-toolbar class="panel-personal" hidden?="{{shortView}}">
...
</core-toolbar>
<core-toolbar class="panel-nav">
<paper-tabs valueattr="hash" selected="{{route}}" selectedModel="{{selectedPage}}"
on-core-select="{{menuItemSelected}}" link flex style="width:100%; height:100%;" id="tabs">
<template repeat="{{page, i in pages}}">
<paper-tab><a href="#{{page.hash}}">{{page.date_month}}<br/><small>{{page.date_year}}</small></a></paper-tab>
</template>
</paper-tabs>
</core-toolbar>
<nav class="menu">
...
</nav>
<div horizontal layout fit>
<core-animated-pages id="pages" selected="{{route}}" valueattr="hash"
transitions="slide-from-right"
on-tap="{{cyclePages}}" flex self-stretch>
<template repeat="{{page, i in pages}}">
<section hash="{{page.hash}}" class="card-wrapper">
<div flex fit>
<div class="card-container" vertical layout fit >
<h1>{{page.name}}</h1>
<h2>{{page.category}}</h2>
<paper-button raised class="project_button"><a href="{{page.link}}" target="_blank"><core-icon icon="social:share" ></core-icon> visit project</a> </paper-button>
</div>
<div center-justified layout fit class="card-content">
<div>
<h4>Project description</h4>
<p>{{page.desc}}
</p>
</div>
</div>
<div class="card-background" id="el" fit></div>
</div>
</section>
</template>
</core-animated-pages>
</div>
</core-header-panel>
</template>
我如何选择那个#el div?
【问题讨论】:
-
哪个
el?您的<div class="card-background" id="el" fit></div>在<template repeat="{{page, i in pages}}">内,因此可能会有多个div#el被标记到 DOM 中。 -
对。我意识到它确实会产生 5 个 id="el" 的 div,所以给那个 div 一个 id 是行不通的。我实际上要做的是在当前选择的页面上为 div.card-background 设置动画。当一个页面被选中时,它有一个“活动”作为参数和一个类“核心选择”。我需要为活动页面 div 启动 play() 函数,但我需要先定位它,我不知道该怎么做。
标签: javascript selector polymer shadow-dom