Man*_*ora 5 javascript polymer polymer-1.0
我试图通过单击一个红色方块来实现英雄动画(从neon-elements)动画到另一个自定义元素(element1.html到element2.html).
我写了这里记录的所有内容:https: //github.com/PolymerElements/neon-animation#shared-element
但点击没有任何反应.请指导我实施这个.
这是我的文件:
的index.html
<!DOCTYPE html>
<html>
<head>
<script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"> </script>
<link rel="import" href="bower_components/neon-animation/neon-animated-pages.html">
<link rel="import" href="bower_components/neon-animation/neon-animations.html">
<link rel="import" href="element1.html">
<link rel="import" href="element2.html">
</head>
<body>
<template is="dom-bind">
<neon-animated-pages id="pages" selected="0">
<name-tag>
</name-tag>
<name-tag1>
</name-tag1>
</neon-animated-pages>
</template>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
element1.html
<link rel="import" href="bower_components/polymer/polymer.html">
<link rel="import" href="bower_components/neon-animation/neon-shared-element-animatable-behavior.html">
<dom-module id="name-tag">
<template>
<div id="hero" style="background:red; width:100px; height:100px; position:absolute; left:100px; top:50px;"></div>
</template>
</dom-module>
<script>
Polymer({
is: "name-tag",
behaviors: [
Polymer.NeonAnimationRunnerBehavior
],
properties: {
animationConfig: {
value: function() {
return {
// the outgoing page defines the 'exit' animation
'exit': {
name: 'hero-animation',
id: 'hero',
fromPage: this
}
}
}
},
sharedElements: {
value: function() {
return {
'hero': this.$.hero
}
}
}
}
});
</script>
Run Code Online (Sandbox Code Playgroud)
element2.html
<link rel="import" href="bower_components/polymer/polymer.html">
<link rel="import" href="bower_components/neon-animation/neon-shared-element-animatable-behavior.html">
<dom-module id="name-tag1">
<template>
<div id="card" style="background:red; width:200px; height:200px; position:absolute; left:300px; top:100px;"></div>
</template>
</dom-module>
<script>
Polymer({
is: "name-tag1",
behaviors: [
Polymer.NeonAnimationRunnerBehavior
],
properties: {
sharedElements: {
type: Object,
value: function() {
return {
'hero': this.$.card,
}
}
},
animationConfig: {
value: function() {
return {
// the incoming page defines the 'entry' animation
'entry': {
name: 'hero-animation',
id: 'hero',
toPage: this
}
}
}
},
}
});
</script>
Run Code Online (Sandbox Code Playgroud)
提前致谢.
小智 1
您正在使用错误的行为。NeonAnimationRunnerBehavior适用于在其内部播放或运行动画的组件。非常好的例子是neon-animated-pages组件,它实现是NeonAnimationRunnerBehavior因为它在内部运行动画。
放入的每一项都neon-animated-pages必须执行NeonAnimatableBehavior,而不是NeonAnimationRunnerBehavior。
要运行动画,我们必须以某种方式在可动画组件之间进行切换。neon-animated-pages的“selected”属性可以帮助我们做到这一点。什么时候selected = "0" neon-animated-pages向你展示name-tag,什么时候selected = "1" neon-animated-pages向你展示name-tag1组件。
您想在单击后更改视图,但我没有看到任何单击事件侦听器。添加将更改所选属性值的点击事件,它将起作用。
| 归档时间: |
|
| 查看次数: |
3634 次 |
| 最近记录: |