Aframe.io: Add border to on mouseover using

2019-08-18 14:55发布

问题:

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)
        });

    }
});