【问题标题】:Aframe Trigger Animation of Element through event-component & proxy-componentAframe 通过 event-component & proxy-component 触发 Element 的动画
【发布时间】:2018-10-25 09:51:30
【问题描述】:

我正在尝试在查看某个元素时触发其他元素上的动画。所以我想要实现的是:当我将球悬停时,文本应该淡入。当我离开球时,文本应该淡出。

有人告诉我,aframe-proxy-event-component 应该可以做到这一点,但我找不到任何关于如何使用它的示例或文档。

代码看起来像这样:

<script src="https://unpkg.com/aframe-animation-component@5.1.2/dist/aframe-animation-component.min.js"></script>
<script src="https://unpkg.com/aframe-event-set-component@4.0.0/dist/aframe-event-set-component.min.js"></script>
<script src="https://unpkg.com/aframe-proxy-event-component/dist/aframe-proxy-event-component.min.js"></script>

<a-mixin id="scaleUpMixin" animation__scale="property: scale; dur: 500; easing: easeInOutQuad; to: 1.5 1.5 1.5;"></a-mixin>
<a-mixin id="scaleDownMixin" animation__scale2="property: scale; dur: 500; easing: easeInOutQuad; to: 1 1 1;"></a-mixin>

<a-mixin id="fadeInText" animation__opacity="property: text.opacity; dur: 500; to: 1"></a-mixin>
<a-mixin id="fadeOutText" animation__opacity2="property: text.opacity; dur: 500; to: 0"></a-mixin>

<a-entity rotation="0 -10 0">
    <!-- Planet -->
    <a-sphere color="yellow" position="0 1.8 -5" radius="0.5" scale="1 1 1" 
        mixin="scaleUpMixin scaleDownMixin"
        animation__scale="startEvents: mouseenter;"
        animation__scale2="startEvents: mouseleave;">
    </a-sphere>

    <!-- Text -->
    <a-text id="TextMercury" class="textbox" text="value: Merkur; align: center; color:#FFF" opacity="0" scale="0.8 0.8 0.8"
        position="0 1.8 -1"> </a-text>

</a-entity>

这是一个现场演示:https://gorgeous-badge.glitch.me/

代码:https://glitch.com/edit/#!/gorgeous-badge?path=index.html:30:61

谢谢!

【问题讨论】:

    标签: animation aframe webvr


    【解决方案1】:

    您需要将proxy-event 组件附加到球体。它有很好的记录(有一个例子)@github

    如果你有一个按钮,你可以像这样重定向任何事件:

    <a-box proxy-event="event: event; to: targetSelector; as: newname"></a-box>
    <a-entity animation="(...) startEvents: newname"></a-entity>
    

    查看this fiddle

    【讨论】:

    • 非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2018-12-10
    • 1970-01-01
    • 2018-12-21
    • 2022-12-28
    • 2016-07-17
    • 2022-12-27
    • 1970-01-01
    • 2019-09-23
    相关资源
    最近更新 更多