简体   繁体   English

A-FRAME 1.0.4 如何正确定义 animation mouseenter 和 mouseleave

[英]A-FRAME 1.0.4 How can I define animation mouseenter and mouseleave properly

I have an entity contain an image using as a button I want to scale that button larger from "1 1 1" to "2 2 1" when mouse hover. I use JS to generate that button.我有一个包含用作按钮的图像的实体我想在鼠标 hover 时将该按钮从“1 1 1”缩放到“2 2 1”。我使用 JS 生成该按钮。 Other attributes are set and working, but the animation doesn't work.其他属性已设置且有效,但 animation 无效。 Could you please show me what is wrong?你能告诉我哪里出了问题吗?


_buttonA.setAttribute("animation__mouseEnter", "property: scale; type: scale; from: 1 1 1; to: 2 2 1; startEvents: mouseenter; dur: 500");

 _buttonA.setAttribute("animation__mouseLeave", "property: scale; type: scale; from: 2 2 1; to: 1 1 1; startEvents: mouseleave; dur: 500");

After generating that object via JS, I see the value of the animation attribute is empty.通过 JS 生成 object 后,我看到 animation 属性的值为空。 I don't know why the setAttribute isn't working properly here.我不知道为什么 setAttribute 在这里不能正常工作。

I try to use: createAttribute and setAttribtueNode as below and it works:我尝试使用:createAttribute 和 setAttribtueNode,如下所示,它有效:

        var animation__mouseEnter = document.createAttribute("animation__mouseEnter");
        var animation__mouseLeave = document.createAttribute("animation__mouseLeave");
        animation__mouseEnter.value ="property: scale; type: scale; from: 1 1 1; to: 1.3 1.3 1; startEvents: mouseenter; dur: 200";
        animation__mouseLeave.value ="property: scale; type: scale; from: 1.3 1.3 1; to: 1 1 1; startEvents: mouseleave; dur: 200";
        buttonA.setAttributeNode(animation__mouseEnter);
        buttonA.setAttributeNode(animation__mouseLeave);

P/S: I can use below setAttribute to set animation for other object: _im.setAttribute("animation__rotation", "property: rotation; loop: true; from: 0 0 0; to: 0 360 0; dur: 5000"); P/S: 我可以使用下面的 setAttribute 为其他 object 设置 animation: _im.setAttribute("animation__rotation", "property: rotation; loop: true; from: 0 0 0; to: 0 360 0; dur: 5000"); and in inspector of chrome browser, it also shows empty, but it works image of the object in inspector在 chrome 浏览器的检查器中,它也显示为空,但它在检查器中显示object 的图像

if using createAttribute and setAttributeNode, the value of animation is displaying fully in the inspector like this snapshot如果使用 createAttribute 和 setAttributeNode,animation 的值将像这个快照一样在检查器中完全显示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM