Javascript to trigger multiple elements in Storyline
A user needed a sample of a Javascript to trigger an audio on all elements on a slide. Offcourse that is possible so i made a sample.
https://360.articulate.com/review/content/a477f9f5-6348-4570-88fd-f9060ecdb7dd/review
Main thing to know is how to get to all page elements you want to be clickable.
Basically this line does that...var allClickableElements = document.querySelectorAll("[data-acc-text*='.png']");
You need some string that is used in all your images on the page. If you want all pngs be clickable...well then the line above creates an array that you can loop and use in Javascript. Depending on your elements you can ofcourse use another string.
In the part of your code where you want to loop through your array to do something with all elements you can use a for if loop. Something like this..
for(var i = 0; i < allClickableElements.length;i++){
allClickableElements[i].addEventListener("mouseup", MouseUpHandler);
allClickableElements[i].addEventListener("mouseup", MouseUpHandler);
}
My complete code looks like this...
In the sample i made i exported all images from Illustrator at double scale. So they get named 'image@2x.png'. This makes it easy for me to select all images with a selector. If you have an existing Storyline where you donot have a proper naming of your assets so you can select all easily... you need to set 'accessibility names' directly in Storyline.
In the image below you see that when importing images in Storyline they get automatically assigned the sources name.
So in the Javascript code we now can select all our elements. In the MouseUpHandler i just set the variable 'playAudio' in Storyline.
In Storyline a trigger on that variable opens up the AudioLayer1 and then the audio plays.
Thats basically it...
Adding my Storyline..