• Resolved arjanbroek

    (@arjanbroek)


    Hi,

    Is there a way to automaticly play sound on hover in the image of the drumkit?

    regards, Arjan

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author Avirtum

    (@avirtum)

    You can try this code below. It will play sound if cursor is under a layer and stop if it leave it. Note: each layer has the userData field, you can use it to store sound URL or for another logics. In this example I just echo this value into the browser log.

    
    const plugin = this;
    const $ = jQuery;
    let audio = null;
    
    plugin.$container.on('mouseover mouseout', '.vision-layer', (e) => {
        const $layer = $(e.currentTarget);
        const layerId = $layer.attr('data-layer-id');
        const layer = plugin.getLayer(layerId);
        
        console.log(layer.cfg.userData);
    
        if(layer) {
            if(audio) {
                audio.pause();
                audio.currentTime = 0;
                audio = null;
            }
            
            if(e.type == 'mouseover') {
                audio = new Audio('https://assets.mixkit.co/active_storage/sfx/940/940-preview.mp3');
                audio.play();
            }
        }
    });
Viewing 1 replies (of 1 total)
  • The topic ‘Sound on hover’ is closed to new replies.