We are about to switch to a new forum software. Until then we have removed the registration on this forum.
been doing a lot of digging for relevant info, but i can't find good examples of audio files being triggered and paused in response to the viewport and/or scrolling. i assume processing would be the best bet. any tips/suggestions?
Answers
I can't find any mention of 'scroll' in the p5js docs, so you may have to use raw JavaScript or another library (jQuery being the obvious one). As for your digging: you just need to find out how to trigger an event on scroll (less specific search so more likely to find an answer) then in that event play your audio file as normal...
thanks - i had a feeling i'd end up needing to start from that point but was hoping i'd overlooked something to reference.
Having looked into it you don't necessarily need an additional library - just depends on your requirements. Simple proof of concept:
The numbers in triggerEvent are arbitrary. If you want to trigger an event when a particular element comes into view you could dynamically get the element's y position and use the above approach. Alternatively a different tack is to ignore scroll position and trigger an event when an element becomes visible. Doing that may be a dark art so with this approach it may be simpler to use a library...
Just to be clear mixing in additional libraries with p5js is perfectly possible; but I'd recommend using instance mode as I have above: otherwise you'll find out why p5js's decision to put everything in the global namespace is really bad. I'd also suggest lightweight libraries wherever possible.
http://p5js.org/reference/#/p5/mouseWheel
thanks @blindfish - i may need some time to see how this will work (still relatively new to js). fingers crossed...
appreciate the reference @gotoloop - what are your thoughts on how the audio would fit into the mouseWheel code?
Dunno. The only thing certain is that the mouse's wheel has rolled.
We can also get its delta in order to know whether it was up or down.