There may be another approach, as shown by @Anke here:
and loosely based on this:
and this:
I have a working html file you can test if you wish...