Aframe.io: Add border to <a-curvedimage> on mouseover using

老子叫甜甜 提交于 2020-01-07 04:45:08

问题


How would I add a border to a curved image when selected?

The following code will change the material color of the image however I'd prefer to add a border or glow instead.

AFRAME.registerComponent('selectable', {

    init: function () {
        var el = this.el;
        this.el.addEventListener('mouseenter', function (evt) {
            this.setAttribute('material', 'color', 'blue');

        });
        this.el.addEventListener('mouseleave', function (evt) {
            this.setAttribute('material', 'color', '');
        });

    }
});

Here is a JSBIN showing showing the above


回答1:


Create a slightly bigger <a-curvedimage> behind yours, but don't give it an image texture src, just provide a solid color and perhaps toggle opacity/visibility.

AFRAME.registerComponent('selectable', {

    init: function () {
        var el = this.el;
        var backgroundEl = el.sceneEl.querySelector('#backgroundEl');
        this.el.addEventListener('mouseenter', function (evt) {
            backgroundEl.setAttribute('visible', true);

        });
        this.el.addEventListener('mouseleave', function (evt) {
            backgroundEl.setAttribute('visible', false)
        });

    }
});


来源:https://stackoverflow.com/questions/45290438/aframe-io-add-border-to-a-curvedimage-on-mouseover-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!